1e41f4b71Sopenharmony_ci# @ohos.multimedia.avsession (AVSession Management)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **avSession** module provides APIs for media playback control so that applications can access the system's Media Controller.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThis module provides the following typical features related to media sessions:
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci- [AVSession](#avsession10): used to set session metadata, playback state information, and more.
8e41f4b71Sopenharmony_ci- [AVSessionController](#avsessioncontroller10): used to obtain session IDs, send commands and events to sessions, and obtain the session metadata and playback state information.
9e41f4b71Sopenharmony_ci- [AVCastController](#avcastcontroller10): used to control playback, listen for remote playback state changes, and obtain the remote playback state in casting scenarios.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci> **NOTE**
12e41f4b71Sopenharmony_ci>
13e41f4b71Sopenharmony_ci> 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.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Modules to Import
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```ts
18e41f4b71Sopenharmony_ciimport { avSession } from '@kit.AVSessionKit';
19e41f4b71Sopenharmony_ci```
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## avSession.createAVSession<sup>10+</sup>
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cicreateAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AVSession>
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciCreates 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.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Parameters**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| Name| Type                           | Mandatory| Description                          |
34e41f4b71Sopenharmony_ci| ------ | ------------------------------- | ---- | ------------------------------ |
35e41f4b71Sopenharmony_ci| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | Yes| Context of the UIAbility, which is used to obtain information about the application component.|
36e41f4b71Sopenharmony_ci| tag    | string                          | Yes  | Custom session name.            |
37e41f4b71Sopenharmony_ci| type   | [AVSessionType](#avsessiontype10) | Yes  | Session type.|
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**Return value**
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| Type                             | Description                                                        |
42e41f4b71Sopenharmony_ci| --------------------------------- | ------------------------------------------------------------ |
43e41f4b71Sopenharmony_ci| 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.|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Error codes**
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci| ID| Error Message|
50e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
51e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
52e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**Example**
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci```ts
57e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession;
60e41f4b71Sopenharmony_cilet tag = "createNewSession";
61e41f4b71Sopenharmony_cilet context: Context = getContext(this);
62e41f4b71Sopenharmony_cilet sessionId: string;  // Used as an input parameter of subsequent functions.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio").then((data: avSession.AVSession) => {
65e41f4b71Sopenharmony_ci  currentAVSession = data;
66e41f4b71Sopenharmony_ci  sessionId = currentAVSession.sessionId;
67e41f4b71Sopenharmony_ci  console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
68e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
69e41f4b71Sopenharmony_ci  console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
70e41f4b71Sopenharmony_ci});
71e41f4b71Sopenharmony_ci```
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci## avSession.createAVSession<sup>10+</sup>
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_cicreateAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ciCreates 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.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**Parameters**
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci| Name  | Type                                   | Mandatory| Description                                                        |
84e41f4b71Sopenharmony_ci| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
85e41f4b71Sopenharmony_ci| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | Yes| Context of the UIAbility, which is used to obtain information about the application component.    |
86e41f4b71Sopenharmony_ci| tag      | string                                  | Yes  | Custom session name.                                          |
87e41f4b71Sopenharmony_ci| type     | [AVSessionType](#avsessiontype10)         | Yes  | Session type.                              |
88e41f4b71Sopenharmony_ci| 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.|
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Error codes**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| ID| Error Message|
95e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
96e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
97e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**Example**
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci```ts
102e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession;
105e41f4b71Sopenharmony_cilet tag = "createNewSession";
106e41f4b71Sopenharmony_cilet context: Context = getContext(this);
107e41f4b71Sopenharmony_cilet sessionId: string;  // Used as an input parameter of subsequent functions.
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
110e41f4b71Sopenharmony_ci  if (err) {
111e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
112e41f4b71Sopenharmony_ci  } else {
113e41f4b71Sopenharmony_ci    currentAVSession = data;
114e41f4b71Sopenharmony_ci    sessionId = currentAVSession.sessionId;
115e41f4b71Sopenharmony_ci    console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
116e41f4b71Sopenharmony_ci  }
117e41f4b71Sopenharmony_ci});
118e41f4b71Sopenharmony_ci```
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci## ProtocolType<sup>11+</sup>
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ciEnumerates the protocol types supported by the remote device.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci| Name                       | Value  | Description        |
129e41f4b71Sopenharmony_ci| --------------------------- | ---- | ----------- |
130e41f4b71Sopenharmony_ci| TYPE_LOCAL<sup>11+</sup>      | 0    | Local device, which can be the built-in speaker or audio jack of the device, or an A2DP device.|
131e41f4b71Sopenharmony_ci| TYPE_CAST_PLUS_STREAM<sup>11+</sup>      | 2    | Cast+ stream mode, indicating that the media asset is being displayed on another device.|
132e41f4b71Sopenharmony_ci| TYPE_DLNA<sup>12+</sup>      | 4    | DLNA protocol, indicating that the media asset is being displayed on another device.|
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci## AVSessionType<sup>10+<sup>
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_citype AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call'
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ciEnumerates the session types supported by the session.
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ciYou can use the strings listed in the following table.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci| Type | Description|
147e41f4b71Sopenharmony_ci| -----  | ---- |
148e41f4b71Sopenharmony_ci| 'audio' | Audio session.|
149e41f4b71Sopenharmony_ci| 'video' | Video session.|
150e41f4b71Sopenharmony_ci| 'voice_call'<sup>11+<sup> | Voice call.|
151e41f4b71Sopenharmony_ci| 'video_call'<sup>12+<sup> | Video call.|
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci## AVSession<sup>10+</sup>
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ciAn **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. 
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci### Attributes
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci| Name     | Type  | Readable| Writable| Description                         |
164e41f4b71Sopenharmony_ci| :-------- | :----- | :--- | :--- | :---------------------------- |
165e41f4b71Sopenharmony_ci| sessionId | string | Yes  | No  | Unique session ID of the **AVSession** object.|
166e41f4b71Sopenharmony_ci| sessionType| [AVSessionType](#avsessiontype10) | Yes  | No  | AVSession type.|
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Example**
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci```ts
171e41f4b71Sopenharmony_cilet sessionId: string = currentAVSession.sessionId;
172e41f4b71Sopenharmony_cilet sessionType: avSession.AVSessionType = currentAVSession.sessionType;
173e41f4b71Sopenharmony_ci```
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci### setAVMetadata<sup>10+</sup>
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_cisetAVMetadata(data: AVMetadata): Promise\<void>
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ciSets session metadata. This API uses a promise to return the result.
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**Parameters**
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci| Name| Type                     | Mandatory| Description        |
188e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- | ------------ |
189e41f4b71Sopenharmony_ci| data   | [AVMetadata](#avmetadata10) | Yes  | Session metadata.|
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci**Return value**
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci| Type          | Description                         |
194e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
195e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci**Error codes**
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci| ID| Error Message|
202e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
203e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
204e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
205e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci**Example**
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci```ts
210e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_cilet metadata: avSession.AVMetadata = {
213e41f4b71Sopenharmony_ci  assetId: "121278",
214e41f4b71Sopenharmony_ci  title: "lose yourself",
215e41f4b71Sopenharmony_ci  artist: "Eminem",
216e41f4b71Sopenharmony_ci  author: "ST",
217e41f4b71Sopenharmony_ci  album: "Slim shady",
218e41f4b71Sopenharmony_ci  writer: "ST",
219e41f4b71Sopenharmony_ci  composer: "ST",
220e41f4b71Sopenharmony_ci  duration: 2222,
221e41f4b71Sopenharmony_ci  mediaImage: "https://www.example.com/example.jpg",
222e41f4b71Sopenharmony_ci  subtitle: "8 Mile",
223e41f4b71Sopenharmony_ci  description: "Rap",
224e41f4b71Sopenharmony_ci  // The LRC contains two types of elements: time tag + lyrics, and ID tag.
225e41f4b71Sopenharmony_ci  // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n
226e41f4b71Sopenharmony_ci  lyric: "Lyrics in LRC format",
227e41f4b71Sopenharmony_ci  previousAssetId: "121277",
228e41f4b71Sopenharmony_ci  nextAssetId: "121279"
229e41f4b71Sopenharmony_ci};
230e41f4b71Sopenharmony_cicurrentAVSession.setAVMetadata(metadata).then(() => {
231e41f4b71Sopenharmony_ci  console.info('SetAVMetadata successfully');
232e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
233e41f4b71Sopenharmony_ci  console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
234e41f4b71Sopenharmony_ci});
235e41f4b71Sopenharmony_ci```
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci### setAVMetadata<sup>10+</sup>
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_cisetAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ciSets session metadata. This API uses an asynchronous callback to return the result.
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci**Parameters**
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                 |
248e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------- |
249e41f4b71Sopenharmony_ci| data     | [AVMetadata](#avmetadata10) | Yes  | Session metadata.                         |
250e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**Error codes**
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci| ID| Error Message|
257e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
258e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
259e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
260e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci**Example**
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci```ts
265e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_cilet metadata: avSession.AVMetadata = {
268e41f4b71Sopenharmony_ci  assetId: "121278",
269e41f4b71Sopenharmony_ci  title: "lose yourself",
270e41f4b71Sopenharmony_ci  artist: "Eminem",
271e41f4b71Sopenharmony_ci  author: "ST",
272e41f4b71Sopenharmony_ci  album: "Slim shady",
273e41f4b71Sopenharmony_ci  writer: "ST",
274e41f4b71Sopenharmony_ci  composer: "ST",
275e41f4b71Sopenharmony_ci  duration: 2222,
276e41f4b71Sopenharmony_ci  mediaImage: "https://www.example.com/example.jpg",
277e41f4b71Sopenharmony_ci  subtitle: "8 Mile",
278e41f4b71Sopenharmony_ci  description: "Rap",
279e41f4b71Sopenharmony_ci  // The LRC contains two types of elements: time tag + lyrics, and ID tag.
280e41f4b71Sopenharmony_ci  // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n
281e41f4b71Sopenharmony_ci  lyric: "Lyrics in LRC format",
282e41f4b71Sopenharmony_ci  previousAssetId: "121277",
283e41f4b71Sopenharmony_ci  nextAssetId: "121279"
284e41f4b71Sopenharmony_ci};
285e41f4b71Sopenharmony_cicurrentAVSession.setAVMetadata(metadata, (err: BusinessError) => {
286e41f4b71Sopenharmony_ci  if (err) {
287e41f4b71Sopenharmony_ci    console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
288e41f4b71Sopenharmony_ci  } else {
289e41f4b71Sopenharmony_ci    console.info('SetAVMetadata successfully');
290e41f4b71Sopenharmony_ci  }
291e41f4b71Sopenharmony_ci});
292e41f4b71Sopenharmony_ci```
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci### setCallMetadata<sup>11+</sup>
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_cisetCallMetadata(data: CallMetadata): Promise\<void>
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ciSets call metadata. This API uses a promise to return the result.
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci**Parameters**
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci| Name| Type                     | Mandatory| Description        |
305e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- | ------------ |
306e41f4b71Sopenharmony_ci| data   | [CallMetadata](#callmetadata11) | Yes  | Call metadata.|
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci**Return value**
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci| Type          | Description                         |
311e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
312e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**Error codes**
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci| ID| Error Message|
319e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
320e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
321e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
322e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci**Example**
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci```ts
327e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
328e41f4b71Sopenharmony_ciimport { resourceManager } from '@kit.LocalizationKit';
329e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_cilet value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
332e41f4b71Sopenharmony_ci    let imageSource = await image.createImageSource(value.buffer);
333e41f4b71Sopenharmony_ci    let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
334e41f4b71Sopenharmony_ci    let calldata: avSession.CallMetadata = {
335e41f4b71Sopenharmony_ci      name: "xiaoming",
336e41f4b71Sopenharmony_ci      phoneNumber: "111xxxxxxxx",
337e41f4b71Sopenharmony_ci      avatar: imagePixel
338e41f4b71Sopenharmony_ci    };
339e41f4b71Sopenharmony_cicurrentAVSession.setCallMetadata(calldata).then(() => {
340e41f4b71Sopenharmony_ci  console.info('setCallMetadata successfully');
341e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
342e41f4b71Sopenharmony_ci  console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
343e41f4b71Sopenharmony_ci});
344e41f4b71Sopenharmony_ci```
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci### setCallMetadata<sup>11+</sup>
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_cisetCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ciSets call metadata. This API uses an asynchronous callback to return the result.
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci**Parameters**
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                 |
357e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------- |
358e41f4b71Sopenharmony_ci| data     | [CallMetadata](#callmetadata11) | Yes  | Call metadata.                         |
359e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**Error codes**
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci| ID| Error Message|
366e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
367e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
368e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
369e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci**Example**
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci```ts
374e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
375e41f4b71Sopenharmony_ciimport { resourceManager } from '@kit.LocalizationKit';
376e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ciasync function setCallMetadata() {
379e41f4b71Sopenharmony_ci  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
380e41f4b71Sopenharmony_ci  let imageSource = await image.createImageSource(value.buffer);
381e41f4b71Sopenharmony_ci  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
382e41f4b71Sopenharmony_ci  let calldata: avSession.CallMetadata = {
383e41f4b71Sopenharmony_ci    name: "xiaoming",
384e41f4b71Sopenharmony_ci    phoneNumber: "111xxxxxxxx",
385e41f4b71Sopenharmony_ci    avatar: imagePixel
386e41f4b71Sopenharmony_ci  };
387e41f4b71Sopenharmony_ci  currentAVSession.setCallMetadata(calldata, (err: BusinessError) => {
388e41f4b71Sopenharmony_ci    if (err) {
389e41f4b71Sopenharmony_ci      console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
390e41f4b71Sopenharmony_ci    } else {
391e41f4b71Sopenharmony_ci      console.info('setCallMetadata successfully');
392e41f4b71Sopenharmony_ci    }
393e41f4b71Sopenharmony_ci  });
394e41f4b71Sopenharmony_ci}
395e41f4b71Sopenharmony_ci```
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci### setAVCallState<sup>11+</sup>
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_cisetAVCallState(state: AVCallState): Promise\<void>
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ciSets the call state. This API uses a promise to return the result.
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci**Parameters**
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci| Name| Type                     | Mandatory| Description        |
408e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- | ------------ |
409e41f4b71Sopenharmony_ci| state   | [AVCallState](#avcallstate11) | Yes  | Call state.|
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci**Return value**
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ci| Type          | Description                         |
414e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
415e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci**Error codes**
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci| ID| Error Message|
422e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
423e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
424e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
425e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci**Example**
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci```ts
430e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_cilet calldata: avSession.AVCallState = {
433e41f4b71Sopenharmony_ci  state: avSession.CallState.CALL_STATE_ACTIVE,
434e41f4b71Sopenharmony_ci  muted: false
435e41f4b71Sopenharmony_ci};
436e41f4b71Sopenharmony_cicurrentAVSession.setAVCallState(calldata).then(() => {
437e41f4b71Sopenharmony_ci  console.info('setAVCallState successfully');
438e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
439e41f4b71Sopenharmony_ci  console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
440e41f4b71Sopenharmony_ci});
441e41f4b71Sopenharmony_ci```
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci### setAVCallState<sup>11+</sup>
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_cisetAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ciSets the call state. This API uses an asynchronous callback to return the result.
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci**Parameters**
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                 |
454e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------- |
455e41f4b71Sopenharmony_ci| state     | [AVCallState](#avcallstate11) | Yes  | Call state.                         |
456e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
457e41f4b71Sopenharmony_ci
458e41f4b71Sopenharmony_ci**Error codes**
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci| ID| Error Message|
463e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
464e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
465e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
466e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci**Example**
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci```ts
471e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_cilet avcalldata: avSession.AVCallState = {
474e41f4b71Sopenharmony_ci  state: avSession.CallState.CALL_STATE_ACTIVE,
475e41f4b71Sopenharmony_ci  muted: false
476e41f4b71Sopenharmony_ci};
477e41f4b71Sopenharmony_cicurrentAVSession.setAVCallState(avcalldata, (err: BusinessError) => {
478e41f4b71Sopenharmony_ci  if (err) {
479e41f4b71Sopenharmony_ci    console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
480e41f4b71Sopenharmony_ci  } else {
481e41f4b71Sopenharmony_ci    console.info('setAVCallState successfully');
482e41f4b71Sopenharmony_ci  }
483e41f4b71Sopenharmony_ci});
484e41f4b71Sopenharmony_ci```
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci### setAVPlaybackState<sup>10+</sup>
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_cisetAVPlaybackState(state: AVPlaybackState): Promise\<void>
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ciSets information related to the session playback state. This API uses a promise to return the result.
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**Parameters**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci| Name| Type                               | Mandatory| Description                                          |
499e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ---------------------------------------------- |
500e41f4b71Sopenharmony_ci| state   | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci**Return value**
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci| Type          | Description                         |
505e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
506e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci**Error codes**
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_ci| ID| Error Message|
513e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
514e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
515e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
516e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ci**Example**
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci```ts
521e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_cilet playbackState: avSession.AVPlaybackState = {
524e41f4b71Sopenharmony_ci  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
525e41f4b71Sopenharmony_ci  speed: 1.0,
526e41f4b71Sopenharmony_ci  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
527e41f4b71Sopenharmony_ci  bufferedTime:1000,
528e41f4b71Sopenharmony_ci  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
529e41f4b71Sopenharmony_ci  isFavorite:true
530e41f4b71Sopenharmony_ci};
531e41f4b71Sopenharmony_cicurrentAVSession.setAVPlaybackState(playbackState).then(() => {
532e41f4b71Sopenharmony_ci  console.info('SetAVPlaybackState successfully');
533e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
534e41f4b71Sopenharmony_ci  console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
535e41f4b71Sopenharmony_ci});
536e41f4b71Sopenharmony_ci```
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci### setAVPlaybackState<sup>10+</sup>
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_cisetAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ciSets information related to the session playback state. This API uses an asynchronous callback to return the result.
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci**Parameters**
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci| Name  | Type                               | Mandatory| Description                                          |
549e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | ---- | ---------------------------------------------- |
550e41f4b71Sopenharmony_ci| state     | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
551e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
552e41f4b71Sopenharmony_ci
553e41f4b71Sopenharmony_ci**Error codes**
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ci| ID| Error Message|
558e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
559e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
560e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
561e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci**Example**
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci```ts
566e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_cilet PlaybackState: avSession.AVPlaybackState = {
569e41f4b71Sopenharmony_ci  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
570e41f4b71Sopenharmony_ci  speed: 1.0,
571e41f4b71Sopenharmony_ci  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
572e41f4b71Sopenharmony_ci  bufferedTime:1000,
573e41f4b71Sopenharmony_ci  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
574e41f4b71Sopenharmony_ci  isFavorite:true
575e41f4b71Sopenharmony_ci};
576e41f4b71Sopenharmony_cicurrentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => {
577e41f4b71Sopenharmony_ci  if (err) {
578e41f4b71Sopenharmony_ci    console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
579e41f4b71Sopenharmony_ci  } else {
580e41f4b71Sopenharmony_ci    console.info('SetAVPlaybackState successfully');
581e41f4b71Sopenharmony_ci  }
582e41f4b71Sopenharmony_ci});
583e41f4b71Sopenharmony_ci```
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci### setLaunchAbility<sup>10+</sup>
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_cisetLaunchAbility(ability: WantAgent): Promise\<void>
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ciSets a launcher ability. This API uses a promise to return the result.
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci**Parameters**
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory| Description                                                       |
598e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
599e41f4b71Sopenharmony_ci| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID.|
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci**Return value**
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci| Type          | Description                         |
604e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
605e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci**Error codes**
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci| ID| Error Message|
612e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
613e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
614e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
615e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ci**Example**
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci```ts
620e41f4b71Sopenharmony_ciimport { wantAgent } from '@kit.AbilityKit';
621e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_ci// WantAgentInfo object.
624e41f4b71Sopenharmony_cilet wantAgentInfo: wantAgent.WantAgentInfo = {
625e41f4b71Sopenharmony_ci  wants: [
626e41f4b71Sopenharmony_ci    {
627e41f4b71Sopenharmony_ci      deviceId: "deviceId",
628e41f4b71Sopenharmony_ci      bundleName: "com.example.myapplication",
629e41f4b71Sopenharmony_ci      abilityName: "EntryAbility",
630e41f4b71Sopenharmony_ci      action: "action1",
631e41f4b71Sopenharmony_ci      entities: ["entity1"],
632e41f4b71Sopenharmony_ci      type: "MIMETYPE",
633e41f4b71Sopenharmony_ci      uri: "key = {true,true,false}",
634e41f4b71Sopenharmony_ci      parameters:
635e41f4b71Sopenharmony_ci        {
636e41f4b71Sopenharmony_ci          mykey0: 2222,
637e41f4b71Sopenharmony_ci          mykey1: [1, 2, 3],
638e41f4b71Sopenharmony_ci          mykey2: "[1, 2, 3]",
639e41f4b71Sopenharmony_ci          mykey3: "ssssssssssssssssssssssssss",
640e41f4b71Sopenharmony_ci          mykey4: [false, true, false],
641e41f4b71Sopenharmony_ci          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
642e41f4b71Sopenharmony_ci          mykey6: true
643e41f4b71Sopenharmony_ci        }
644e41f4b71Sopenharmony_ci    }
645e41f4b71Sopenharmony_ci  ],
646e41f4b71Sopenharmony_ci  operationType: wantAgent.OperationType.START_ABILITIES,
647e41f4b71Sopenharmony_ci  requestCode: 0,
648e41f4b71Sopenharmony_ci  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
649e41f4b71Sopenharmony_ci}
650e41f4b71Sopenharmony_ci
651e41f4b71Sopenharmony_ciwantAgent.getWantAgent(wantAgentInfo).then((agent) => {
652e41f4b71Sopenharmony_ci  currentAVSession.setLaunchAbility(agent).then(() => {
653e41f4b71Sopenharmony_ci    console.info('SetLaunchAbility successfully');
654e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
655e41f4b71Sopenharmony_ci    console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
656e41f4b71Sopenharmony_ci  });
657e41f4b71Sopenharmony_ci});
658e41f4b71Sopenharmony_ci```
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci### setLaunchAbility<sup>10+</sup>
661e41f4b71Sopenharmony_ci
662e41f4b71Sopenharmony_cisetLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void
663e41f4b71Sopenharmony_ci
664e41f4b71Sopenharmony_ciSets a launcher ability. This API uses an asynchronous callback to return the result.
665e41f4b71Sopenharmony_ci
666e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ci**Parameters**
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_ci| Name  | Type                                         | Mandatory| Description                                                        |
671e41f4b71Sopenharmony_ci| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
672e41f4b71Sopenharmony_ci| ability  | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID. |
673e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci**Error codes**
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ci| ID| Error Message|
680e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
681e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
682e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
683e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci**Example**
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci```ts
688e41f4b71Sopenharmony_ciimport { wantAgent } from '@kit.AbilityKit';
689e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci// WantAgentInfo object.
692e41f4b71Sopenharmony_cilet wantAgentInfo: wantAgent.WantAgentInfo = {
693e41f4b71Sopenharmony_ci  wants: [
694e41f4b71Sopenharmony_ci    {
695e41f4b71Sopenharmony_ci      deviceId: "deviceId",
696e41f4b71Sopenharmony_ci      bundleName: "com.example.myapplication",
697e41f4b71Sopenharmony_ci      abilityName: "EntryAbility",
698e41f4b71Sopenharmony_ci      action: "action1",
699e41f4b71Sopenharmony_ci      entities: ["entity1"],
700e41f4b71Sopenharmony_ci      type: "MIMETYPE",
701e41f4b71Sopenharmony_ci      uri: "key = {true,true,false}",
702e41f4b71Sopenharmony_ci      parameters:
703e41f4b71Sopenharmony_ci        {
704e41f4b71Sopenharmony_ci          mykey0: 2222,
705e41f4b71Sopenharmony_ci          mykey1: [1, 2, 3],
706e41f4b71Sopenharmony_ci          mykey2: "[1, 2, 3]",
707e41f4b71Sopenharmony_ci          mykey3: "ssssssssssssssssssssssssss",
708e41f4b71Sopenharmony_ci          mykey4: [false, true, false],
709e41f4b71Sopenharmony_ci          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
710e41f4b71Sopenharmony_ci          mykey6: true
711e41f4b71Sopenharmony_ci        }
712e41f4b71Sopenharmony_ci    }
713e41f4b71Sopenharmony_ci  ],
714e41f4b71Sopenharmony_ci  operationType: wantAgent.OperationType.START_ABILITIES,
715e41f4b71Sopenharmony_ci  requestCode: 0,
716e41f4b71Sopenharmony_ci  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
717e41f4b71Sopenharmony_ci}
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ciwantAgent.getWantAgent(wantAgentInfo).then((agent) => {
720e41f4b71Sopenharmony_ci  currentAVSession.setLaunchAbility(agent, (err: BusinessError) => {
721e41f4b71Sopenharmony_ci    if (err) {
722e41f4b71Sopenharmony_ci      console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
723e41f4b71Sopenharmony_ci    } else {
724e41f4b71Sopenharmony_ci      console.info('SetLaunchAbility successfully');
725e41f4b71Sopenharmony_ci    }
726e41f4b71Sopenharmony_ci  });
727e41f4b71Sopenharmony_ci});
728e41f4b71Sopenharmony_ci```
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci### dispatchSessionEvent<sup>10+</sup>
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_cidispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void>
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ciDispatches 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.
735e41f4b71Sopenharmony_ci
736e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
737e41f4b71Sopenharmony_ci
738e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_ci**Parameters**
741e41f4b71Sopenharmony_ci
742e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory| Description                                                       |
743e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
744e41f4b71Sopenharmony_ci| event | string | Yes  | Name of the session event.|
745e41f4b71Sopenharmony_ci| args | {[key: string]: Object} | Yes  | Content of the session event.|
746e41f4b71Sopenharmony_ci
747e41f4b71Sopenharmony_ci> **NOTE**
748e41f4b71Sopenharmony_ci> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ci**Return value**
751e41f4b71Sopenharmony_ci
752e41f4b71Sopenharmony_ci| Type          | Description                         |
753e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
754e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci**Error codes**
757e41f4b71Sopenharmony_ci
758e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
759e41f4b71Sopenharmony_ci
760e41f4b71Sopenharmony_ci| ID| Error Message|
761e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
762e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
763e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
764e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ci**Example**
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci```ts
769e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
772e41f4b71Sopenharmony_cilet tag = "createNewSession";
773e41f4b71Sopenharmony_cilet context: Context = getContext(this);
774e41f4b71Sopenharmony_ci
775e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
776e41f4b71Sopenharmony_ci  if (err) {
777e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
778e41f4b71Sopenharmony_ci  } else {
779e41f4b71Sopenharmony_ci    currentAVSession = data;
780e41f4b71Sopenharmony_ci  }
781e41f4b71Sopenharmony_ci});
782e41f4b71Sopenharmony_cilet eventName = "dynamic_lyric";
783e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
784e41f4b71Sopenharmony_ci  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => {
785e41f4b71Sopenharmony_ci    console.info('dispatchSessionEvent successfully');
786e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
787e41f4b71Sopenharmony_ci    console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
788e41f4b71Sopenharmony_ci  })
789e41f4b71Sopenharmony_ci}
790e41f4b71Sopenharmony_ci```
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ci### dispatchSessionEvent<sup>10+</sup>
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_cidispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
795e41f4b71Sopenharmony_ci
796e41f4b71Sopenharmony_ciDispatches 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.
797e41f4b71Sopenharmony_ci
798e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
799e41f4b71Sopenharmony_ci
800e41f4b71Sopenharmony_ci**Parameters**
801e41f4b71Sopenharmony_ci
802e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory| Description                                                       |
803e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
804e41f4b71Sopenharmony_ci| event | string | Yes  | Name of the session event.|
805e41f4b71Sopenharmony_ci| args | {[key: string]: Object} | Yes  | Content of the session event.|
806e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
807e41f4b71Sopenharmony_ci
808e41f4b71Sopenharmony_ci> **NOTE**
809e41f4b71Sopenharmony_ci
810e41f4b71Sopenharmony_ci> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
811e41f4b71Sopenharmony_ci
812e41f4b71Sopenharmony_ci**Error codes**
813e41f4b71Sopenharmony_ci
814e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
815e41f4b71Sopenharmony_ci
816e41f4b71Sopenharmony_ci| ID| Error Message|
817e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
818e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
819e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
820e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
821e41f4b71Sopenharmony_ci
822e41f4b71Sopenharmony_ci**Example**
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci```ts
825e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
828e41f4b71Sopenharmony_cilet tag = "createNewSession";
829e41f4b71Sopenharmony_cilet context: Context = getContext(this);
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
832e41f4b71Sopenharmony_ci  if (err) {
833e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
834e41f4b71Sopenharmony_ci  } else {
835e41f4b71Sopenharmony_ci    currentAVSession = data;
836e41f4b71Sopenharmony_ci  }
837e41f4b71Sopenharmony_ci});
838e41f4b71Sopenharmony_cilet eventName: string = "dynamic_lyric";
839e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
840e41f4b71Sopenharmony_ci  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => {
841e41f4b71Sopenharmony_ci    if (err) {
842e41f4b71Sopenharmony_ci      console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
843e41f4b71Sopenharmony_ci    }
844e41f4b71Sopenharmony_ci  })
845e41f4b71Sopenharmony_ci}
846e41f4b71Sopenharmony_ci```
847e41f4b71Sopenharmony_ci
848e41f4b71Sopenharmony_ci### setAVQueueItems<sup>10+</sup>
849e41f4b71Sopenharmony_ci
850e41f4b71Sopenharmony_cisetAVQueueItems(items: Array\<AVQueueItem>): Promise\<void>
851e41f4b71Sopenharmony_ci
852e41f4b71Sopenharmony_ciSets a playlist. This API uses a promise to return the result.
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci**Parameters**
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ci| Name | Type                                | Mandatory| Description                              |
861e41f4b71Sopenharmony_ci| ------ | ------------------------------------ | ---- | ---------------------------------- |
862e41f4b71Sopenharmony_ci| items  | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.|
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci**Return value**
865e41f4b71Sopenharmony_ci
866e41f4b71Sopenharmony_ci| Type          | Description                         |
867e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
868e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci**Error codes**
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci| ID| Error Message|
875e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
876e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
877e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
878e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
879e41f4b71Sopenharmony_ci
880e41f4b71Sopenharmony_ci**Example**
881e41f4b71Sopenharmony_ci
882e41f4b71Sopenharmony_ci```ts
883e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
884e41f4b71Sopenharmony_ciimport { resourceManager } from '@kit.LocalizationKit';
885e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
886e41f4b71Sopenharmony_ci
887e41f4b71Sopenharmony_ciasync function setAVQueueItems() {
888e41f4b71Sopenharmony_ci  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
889e41f4b71Sopenharmony_ci  let imageSource = await image.createImageSource(value.buffer);
890e41f4b71Sopenharmony_ci  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
891e41f4b71Sopenharmony_ci  let queueItemDescription_1: avSession.AVMediaDescription = {
892e41f4b71Sopenharmony_ci    assetId: '001',
893e41f4b71Sopenharmony_ci    title: 'music_name',
894e41f4b71Sopenharmony_ci    subtitle: 'music_sub_name',
895e41f4b71Sopenharmony_ci    description: 'music_description',
896e41f4b71Sopenharmony_ci    mediaImage : imagePixel,
897e41f4b71Sopenharmony_ci    extras: {extras:'any'}
898e41f4b71Sopenharmony_ci  };
899e41f4b71Sopenharmony_ci  let queueItem_1: avSession.AVQueueItem = {
900e41f4b71Sopenharmony_ci    itemId: 1,
901e41f4b71Sopenharmony_ci    description: queueItemDescription_1
902e41f4b71Sopenharmony_ci  };
903e41f4b71Sopenharmony_ci  let queueItemDescription_2: avSession.AVMediaDescription = {
904e41f4b71Sopenharmony_ci    assetId: '002',
905e41f4b71Sopenharmony_ci    title: 'music_name',
906e41f4b71Sopenharmony_ci    subtitle: 'music_sub_name',
907e41f4b71Sopenharmony_ci    description: 'music_description',
908e41f4b71Sopenharmony_ci    mediaImage: imagePixel,
909e41f4b71Sopenharmony_ci    extras: {extras:'any'}
910e41f4b71Sopenharmony_ci  };
911e41f4b71Sopenharmony_ci  let queueItem_2: avSession.AVQueueItem = {
912e41f4b71Sopenharmony_ci    itemId: 2,
913e41f4b71Sopenharmony_ci    description: queueItemDescription_2
914e41f4b71Sopenharmony_ci  };
915e41f4b71Sopenharmony_ci  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
916e41f4b71Sopenharmony_ci  currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
917e41f4b71Sopenharmony_ci    console.info('SetAVQueueItems successfully');
918e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
919e41f4b71Sopenharmony_ci    console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
920e41f4b71Sopenharmony_ci  });
921e41f4b71Sopenharmony_ci}
922e41f4b71Sopenharmony_ci```
923e41f4b71Sopenharmony_ci
924e41f4b71Sopenharmony_ci### setAVQueueItems<sup>10+</sup>
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_cisetAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void
927e41f4b71Sopenharmony_ci
928e41f4b71Sopenharmony_ciSets a playlist. This API uses an asynchronous callback to return the result.
929e41f4b71Sopenharmony_ci
930e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
931e41f4b71Sopenharmony_ci
932e41f4b71Sopenharmony_ci**Parameters**
933e41f4b71Sopenharmony_ci
934e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                                        |
935e41f4b71Sopenharmony_ci| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- |
936e41f4b71Sopenharmony_ci| items    | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.                         |
937e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                 | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ci**Error codes**
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci| ID| Error Message|
944e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
945e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
946e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
947e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci**Example**
950e41f4b71Sopenharmony_ci
951e41f4b71Sopenharmony_ci```ts
952e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
953e41f4b71Sopenharmony_ciimport { resourceManager } from '@kit.LocalizationKit';
954e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
955e41f4b71Sopenharmony_ci
956e41f4b71Sopenharmony_ciasync function setAVQueueItems() {
957e41f4b71Sopenharmony_ci  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
958e41f4b71Sopenharmony_ci  let imageSource = await image.createImageSource(value.buffer);
959e41f4b71Sopenharmony_ci  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
960e41f4b71Sopenharmony_ci  let queueItemDescription_1: avSession.AVMediaDescription = {
961e41f4b71Sopenharmony_ci    assetId: '001',
962e41f4b71Sopenharmony_ci    title: 'music_name',
963e41f4b71Sopenharmony_ci    subtitle: 'music_sub_name',
964e41f4b71Sopenharmony_ci    description: 'music_description',
965e41f4b71Sopenharmony_ci    mediaImage : imagePixel,
966e41f4b71Sopenharmony_ci    extras: {extras:'any'}
967e41f4b71Sopenharmony_ci  };
968e41f4b71Sopenharmony_ci  let queueItem_1: avSession.AVQueueItem = {
969e41f4b71Sopenharmony_ci    itemId: 1,
970e41f4b71Sopenharmony_ci    description: queueItemDescription_1
971e41f4b71Sopenharmony_ci  };
972e41f4b71Sopenharmony_ci  let queueItemDescription_2: avSession.AVMediaDescription = {
973e41f4b71Sopenharmony_ci    assetId: '002',
974e41f4b71Sopenharmony_ci    title: 'music_name',
975e41f4b71Sopenharmony_ci    subtitle: 'music_sub_name',
976e41f4b71Sopenharmony_ci    description: 'music_description',
977e41f4b71Sopenharmony_ci    mediaImage: imagePixel,
978e41f4b71Sopenharmony_ci    extras: {extras:'any'}
979e41f4b71Sopenharmony_ci  };
980e41f4b71Sopenharmony_ci  let queueItem_2: avSession.AVQueueItem = {
981e41f4b71Sopenharmony_ci    itemId: 2,
982e41f4b71Sopenharmony_ci    description: queueItemDescription_2
983e41f4b71Sopenharmony_ci  };
984e41f4b71Sopenharmony_ci  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
985e41f4b71Sopenharmony_ci  currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => {
986e41f4b71Sopenharmony_ci    if (err) {
987e41f4b71Sopenharmony_ci      console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
988e41f4b71Sopenharmony_ci    } else {
989e41f4b71Sopenharmony_ci      console.info('SetAVQueueItems successfully');
990e41f4b71Sopenharmony_ci    }
991e41f4b71Sopenharmony_ci  });
992e41f4b71Sopenharmony_ci}
993e41f4b71Sopenharmony_ci```
994e41f4b71Sopenharmony_ci
995e41f4b71Sopenharmony_ci### setAVQueueTitle<sup>10+</sup>
996e41f4b71Sopenharmony_ci
997e41f4b71Sopenharmony_cisetAVQueueTitle(title: string): Promise\<void>
998e41f4b71Sopenharmony_ci
999e41f4b71Sopenharmony_ciSets a name for the playlist. This API uses a promise to return the result.
1000e41f4b71Sopenharmony_ci
1001e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1002e41f4b71Sopenharmony_ci
1003e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1004e41f4b71Sopenharmony_ci
1005e41f4b71Sopenharmony_ci**Parameters**
1006e41f4b71Sopenharmony_ci
1007e41f4b71Sopenharmony_ci| Name | Type  | Mandatory| Description          |
1008e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- |
1009e41f4b71Sopenharmony_ci| title  | string | Yes  | Name of the playlist.|
1010e41f4b71Sopenharmony_ci
1011e41f4b71Sopenharmony_ci**Return value**
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci| Type          | Description                         |
1014e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
1015e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ci**Error codes**
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci| ID| Error Message|
1022e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1023e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1024e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1025e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1026e41f4b71Sopenharmony_ci
1027e41f4b71Sopenharmony_ci**Example**
1028e41f4b71Sopenharmony_ci
1029e41f4b71Sopenharmony_ci```ts
1030e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1031e41f4b71Sopenharmony_ci
1032e41f4b71Sopenharmony_cilet queueTitle = 'QUEUE_TITLE';
1033e41f4b71Sopenharmony_cicurrentAVSession.setAVQueueTitle(queueTitle).then(() => {
1034e41f4b71Sopenharmony_ci  console.info('SetAVQueueTitle successfully');
1035e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1036e41f4b71Sopenharmony_ci  console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1037e41f4b71Sopenharmony_ci});
1038e41f4b71Sopenharmony_ci```
1039e41f4b71Sopenharmony_ci
1040e41f4b71Sopenharmony_ci### setAVQueueTitle<sup>10+</sup>
1041e41f4b71Sopenharmony_ci
1042e41f4b71Sopenharmony_cisetAVQueueTitle(title: string, callback: AsyncCallback\<void>): void
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_ciSets a name for the playlist. This API uses an asynchronous callback to return the result.
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**Parameters**
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                                        |
1051e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ----------------------------------------------------------- |
1052e41f4b71Sopenharmony_ci| title    | string                | Yes  | Name of the playlist.                         |
1053e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1054e41f4b71Sopenharmony_ci
1055e41f4b71Sopenharmony_ci**Error codes**
1056e41f4b71Sopenharmony_ci
1057e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1058e41f4b71Sopenharmony_ci
1059e41f4b71Sopenharmony_ci| ID| Error Message|
1060e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1061e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1062e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1063e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1064e41f4b71Sopenharmony_ci
1065e41f4b71Sopenharmony_ci**Example**
1066e41f4b71Sopenharmony_ci
1067e41f4b71Sopenharmony_ci```ts
1068e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1069e41f4b71Sopenharmony_ci
1070e41f4b71Sopenharmony_cilet queueTitle = 'QUEUE_TITLE';
1071e41f4b71Sopenharmony_cicurrentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => {
1072e41f4b71Sopenharmony_ci  if (err) {
1073e41f4b71Sopenharmony_ci    console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1074e41f4b71Sopenharmony_ci  } else {
1075e41f4b71Sopenharmony_ci    console.info('SetAVQueueTitle successfully');
1076e41f4b71Sopenharmony_ci  }
1077e41f4b71Sopenharmony_ci});
1078e41f4b71Sopenharmony_ci```
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_ci### setExtras<sup>10+</sup>
1081e41f4b71Sopenharmony_ci
1082e41f4b71Sopenharmony_cisetExtras(extras: {[key: string]: Object}): Promise\<void>
1083e41f4b71Sopenharmony_ci
1084e41f4b71Sopenharmony_ciSets 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.
1085e41f4b71Sopenharmony_ci
1086e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1087e41f4b71Sopenharmony_ci
1088e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci**Parameters**
1091e41f4b71Sopenharmony_ci
1092e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory| Description                                                       |
1093e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1094e41f4b71Sopenharmony_ci| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|
1095e41f4b71Sopenharmony_ci
1096e41f4b71Sopenharmony_ci> **NOTE**
1097e41f4b71Sopenharmony_ci
1098e41f4b71Sopenharmony_ci> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
1099e41f4b71Sopenharmony_ci
1100e41f4b71Sopenharmony_ci**Return value**
1101e41f4b71Sopenharmony_ci
1102e41f4b71Sopenharmony_ci| Type          | Description                         |
1103e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
1104e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1105e41f4b71Sopenharmony_ci
1106e41f4b71Sopenharmony_ci**Error codes**
1107e41f4b71Sopenharmony_ci
1108e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1109e41f4b71Sopenharmony_ci
1110e41f4b71Sopenharmony_ci| ID| Error Message|
1111e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1112e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1113e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1114e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1115e41f4b71Sopenharmony_ci
1116e41f4b71Sopenharmony_ci**Example**
1117e41f4b71Sopenharmony_ci
1118e41f4b71Sopenharmony_ci```ts
1119e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
1122e41f4b71Sopenharmony_cilet tag = "createNewSession";
1123e41f4b71Sopenharmony_cilet context: Context = getContext(this);
1124e41f4b71Sopenharmony_ci
1125e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1126e41f4b71Sopenharmony_ci  if (err) {
1127e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1128e41f4b71Sopenharmony_ci  } else {
1129e41f4b71Sopenharmony_ci    currentAVSession = data;
1130e41f4b71Sopenharmony_ci  }
1131e41f4b71Sopenharmony_ci});
1132e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
1133e41f4b71Sopenharmony_ci  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => {
1134e41f4b71Sopenharmony_ci    console.info('setExtras successfully');
1135e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
1136e41f4b71Sopenharmony_ci    console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1137e41f4b71Sopenharmony_ci  })
1138e41f4b71Sopenharmony_ci}
1139e41f4b71Sopenharmony_ci```
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci### setExtras<sup>10+</sup>
1142e41f4b71Sopenharmony_ci
1143e41f4b71Sopenharmony_cisetExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void
1144e41f4b71Sopenharmony_ci
1145e41f4b71Sopenharmony_ciSets 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.
1146e41f4b71Sopenharmony_ci
1147e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1148e41f4b71Sopenharmony_ci
1149e41f4b71Sopenharmony_ci**Parameters**
1150e41f4b71Sopenharmony_ci
1151e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory| Description                                                       |
1152e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1153e41f4b71Sopenharmony_ci| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|
1154e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ci> **NOTE**
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ci> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
1159e41f4b71Sopenharmony_ci
1160e41f4b71Sopenharmony_ci**Error codes**
1161e41f4b71Sopenharmony_ci
1162e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci| ID| Error Message|
1165e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1166e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1167e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1168e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1169e41f4b71Sopenharmony_ci
1170e41f4b71Sopenharmony_ci**Example**
1171e41f4b71Sopenharmony_ci
1172e41f4b71Sopenharmony_ci```ts
1173e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1174e41f4b71Sopenharmony_ci
1175e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
1176e41f4b71Sopenharmony_cilet tag = "createNewSession";
1177e41f4b71Sopenharmony_cilet context: Context = getContext(this);
1178e41f4b71Sopenharmony_ci
1179e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1180e41f4b71Sopenharmony_ci  if (err) {
1181e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1182e41f4b71Sopenharmony_ci  } else {
1183e41f4b71Sopenharmony_ci    currentAVSession = data;
1184e41f4b71Sopenharmony_ci  }
1185e41f4b71Sopenharmony_ci});
1186e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
1187e41f4b71Sopenharmony_ci  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => {
1188e41f4b71Sopenharmony_ci    if (err) {
1189e41f4b71Sopenharmony_ci      console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1190e41f4b71Sopenharmony_ci    }
1191e41f4b71Sopenharmony_ci  })
1192e41f4b71Sopenharmony_ci}
1193e41f4b71Sopenharmony_ci```
1194e41f4b71Sopenharmony_ci
1195e41f4b71Sopenharmony_ci### getController<sup>10+</sup>
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_cigetController(): Promise\<AVSessionController>
1198e41f4b71Sopenharmony_ci
1199e41f4b71Sopenharmony_ciObtains the controller corresponding to this session. This API uses a promise to return the result.
1200e41f4b71Sopenharmony_ci
1201e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1202e41f4b71Sopenharmony_ci
1203e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1204e41f4b71Sopenharmony_ci
1205e41f4b71Sopenharmony_ci**Return value**
1206e41f4b71Sopenharmony_ci
1207e41f4b71Sopenharmony_ci| Type                                                | Description                         |
1208e41f4b71Sopenharmony_ci| ---------------------------------------------------- | ----------------------------- |
1209e41f4b71Sopenharmony_ci| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.|
1210e41f4b71Sopenharmony_ci
1211e41f4b71Sopenharmony_ci**Error codes**
1212e41f4b71Sopenharmony_ci
1213e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1214e41f4b71Sopenharmony_ci
1215e41f4b71Sopenharmony_ci| ID| Error Message|
1216e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1217e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1218e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1219e41f4b71Sopenharmony_ci
1220e41f4b71Sopenharmony_ci**Example**
1221e41f4b71Sopenharmony_ci
1222e41f4b71Sopenharmony_ci```ts
1223e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1224e41f4b71Sopenharmony_ci
1225e41f4b71Sopenharmony_cilet avsessionController: avSession.AVSessionController;
1226e41f4b71Sopenharmony_cicurrentAVSession.getController().then((avcontroller: avSession.AVSessionController) => {
1227e41f4b71Sopenharmony_ci  avsessionController = avcontroller;
1228e41f4b71Sopenharmony_ci  console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1229e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1230e41f4b71Sopenharmony_ci  console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1231e41f4b71Sopenharmony_ci});
1232e41f4b71Sopenharmony_ci```
1233e41f4b71Sopenharmony_ci
1234e41f4b71Sopenharmony_ci### getController<sup>10+</sup>
1235e41f4b71Sopenharmony_ci
1236e41f4b71Sopenharmony_cigetController(callback: AsyncCallback\<AVSessionController>): void
1237e41f4b71Sopenharmony_ci
1238e41f4b71Sopenharmony_ciObtains the controller corresponding to this session. This API uses an asynchronous callback to return the result.
1239e41f4b71Sopenharmony_ci
1240e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1241e41f4b71Sopenharmony_ci
1242e41f4b71Sopenharmony_ci**Parameters**
1243e41f4b71Sopenharmony_ci
1244e41f4b71Sopenharmony_ci| Name  | Type                                                       | Mandatory| Description                      |
1245e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | -------------------------- |
1246e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes  | Callback used to return the session controller.|
1247e41f4b71Sopenharmony_ci
1248e41f4b71Sopenharmony_ci**Error codes**
1249e41f4b71Sopenharmony_ci
1250e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1251e41f4b71Sopenharmony_ci
1252e41f4b71Sopenharmony_ci| ID| Error Message|
1253e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1254e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1255e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1256e41f4b71Sopenharmony_ci
1257e41f4b71Sopenharmony_ci**Example**
1258e41f4b71Sopenharmony_ci
1259e41f4b71Sopenharmony_ci```ts
1260e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1261e41f4b71Sopenharmony_ci
1262e41f4b71Sopenharmony_cilet avsessionController: avSession.AVSessionController;
1263e41f4b71Sopenharmony_cicurrentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => {
1264e41f4b71Sopenharmony_ci  if (err) {
1265e41f4b71Sopenharmony_ci    console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1266e41f4b71Sopenharmony_ci  } else {
1267e41f4b71Sopenharmony_ci    avsessionController = avcontroller;
1268e41f4b71Sopenharmony_ci    console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1269e41f4b71Sopenharmony_ci  }
1270e41f4b71Sopenharmony_ci});
1271e41f4b71Sopenharmony_ci```
1272e41f4b71Sopenharmony_ci
1273e41f4b71Sopenharmony_ci### getAVCastController<sup>10+</sup>
1274e41f4b71Sopenharmony_ci
1275e41f4b71Sopenharmony_cigetAVCastController(callback: AsyncCallback\<AVCastController>): void
1276e41f4b71Sopenharmony_ci
1277e41f4b71Sopenharmony_ciObtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. If the session is not in the cast state, the controller returns **null**.
1278e41f4b71Sopenharmony_ci
1279e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1280e41f4b71Sopenharmony_ci
1281e41f4b71Sopenharmony_ci**Parameters**
1282e41f4b71Sopenharmony_ci
1283e41f4b71Sopenharmony_ci| Name   | Type                                                       | Mandatory| Description                                                        |
1284e41f4b71Sopenharmony_ci| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1285e41f4b71Sopenharmony_ci| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes  | Callback used to return the cast controller.|
1286e41f4b71Sopenharmony_ci
1287e41f4b71Sopenharmony_ci**Error codes**
1288e41f4b71Sopenharmony_ci
1289e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1290e41f4b71Sopenharmony_ci
1291e41f4b71Sopenharmony_ci| ID| Error Message                                 |
1292e41f4b71Sopenharmony_ci| -------- |---------------------------------------|
1293e41f4b71Sopenharmony_ci| 6600102| The session does not exist.           |
1294e41f4b71Sopenharmony_ci| 6600109| The remote connection is not established. |
1295e41f4b71Sopenharmony_ci
1296e41f4b71Sopenharmony_ci**Example**
1297e41f4b71Sopenharmony_ci
1298e41f4b71Sopenharmony_ci```ts
1299e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1300e41f4b71Sopenharmony_ci
1301e41f4b71Sopenharmony_cilet aVCastController: avSession.AVCastController;
1302e41f4b71Sopenharmony_cicurrentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => {
1303e41f4b71Sopenharmony_ci  aVCastController = avcontroller;
1304e41f4b71Sopenharmony_ci  console.info('getAVCastController : SUCCESS');
1305e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1306e41f4b71Sopenharmony_ci  console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1307e41f4b71Sopenharmony_ci});
1308e41f4b71Sopenharmony_ci```
1309e41f4b71Sopenharmony_ci
1310e41f4b71Sopenharmony_ci### getAVCastController<sup>10+</sup>
1311e41f4b71Sopenharmony_ci
1312e41f4b71Sopenharmony_cigetAVCastController(): Promise\<AVCastController>
1313e41f4b71Sopenharmony_ci
1314e41f4b71Sopenharmony_ciObtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. If the session is not in the cast state, the controller returns **null**.
1315e41f4b71Sopenharmony_ci
1316e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1317e41f4b71Sopenharmony_ci
1318e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1319e41f4b71Sopenharmony_ci
1320e41f4b71Sopenharmony_ci**Return value**
1321e41f4b71Sopenharmony_ci
1322e41f4b71Sopenharmony_ci| Type                                                       | Description                                                        |
1323e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------------ |
1324e41f4b71Sopenharmony_ci| Promise<[AVCastController](#avcastcontroller10)\>  | Promise used to return the cast controller.|
1325e41f4b71Sopenharmony_ci
1326e41f4b71Sopenharmony_ci**Error codes**
1327e41f4b71Sopenharmony_ci
1328e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1329e41f4b71Sopenharmony_ci
1330e41f4b71Sopenharmony_ci| ID| Error Message|
1331e41f4b71Sopenharmony_ci| -------- | --------------------------------------- |
1332e41f4b71Sopenharmony_ci| 6600102| The session does not exist.           |
1333e41f4b71Sopenharmony_ci| 6600109| The remote connection is not established. |
1334e41f4b71Sopenharmony_ci
1335e41f4b71Sopenharmony_ci**Example**
1336e41f4b71Sopenharmony_ci
1337e41f4b71Sopenharmony_ci```ts
1338e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1339e41f4b71Sopenharmony_ci
1340e41f4b71Sopenharmony_cilet aVCastController: avSession.AVCastController;
1341e41f4b71Sopenharmony_cicurrentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => {
1342e41f4b71Sopenharmony_ci  if (err) {
1343e41f4b71Sopenharmony_ci    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1344e41f4b71Sopenharmony_ci  } else {
1345e41f4b71Sopenharmony_ci    aVCastController = avcontroller;
1346e41f4b71Sopenharmony_ci    console.info('getAVCastController : SUCCESS');
1347e41f4b71Sopenharmony_ci  }
1348e41f4b71Sopenharmony_ci});
1349e41f4b71Sopenharmony_ci```
1350e41f4b71Sopenharmony_ci
1351e41f4b71Sopenharmony_ci### getOutputDevice<sup>10+</sup>
1352e41f4b71Sopenharmony_ci
1353e41f4b71Sopenharmony_cigetOutputDevice(): Promise\<OutputDeviceInfo>
1354e41f4b71Sopenharmony_ci
1355e41f4b71Sopenharmony_ciObtains information about the output device for this session. This API uses a promise to return the result.
1356e41f4b71Sopenharmony_ci
1357e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1360e41f4b71Sopenharmony_ci
1361e41f4b71Sopenharmony_ci**Return value**
1362e41f4b71Sopenharmony_ci
1363e41f4b71Sopenharmony_ci| Type                                          | Description                             |
1364e41f4b71Sopenharmony_ci| ---------------------------------------------- | --------------------------------- |
1365e41f4b71Sopenharmony_ci| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.|
1366e41f4b71Sopenharmony_ci
1367e41f4b71Sopenharmony_ci**Error codes**
1368e41f4b71Sopenharmony_ci
1369e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1370e41f4b71Sopenharmony_ci
1371e41f4b71Sopenharmony_ci| ID| Error Message|
1372e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1373e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1374e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1375e41f4b71Sopenharmony_ci
1376e41f4b71Sopenharmony_ci**Example**
1377e41f4b71Sopenharmony_ci
1378e41f4b71Sopenharmony_ci```ts
1379e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1380e41f4b71Sopenharmony_ci
1381e41f4b71Sopenharmony_cicurrentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => {
1382e41f4b71Sopenharmony_ci  console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1383e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1384e41f4b71Sopenharmony_ci  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1385e41f4b71Sopenharmony_ci})
1386e41f4b71Sopenharmony_ci```
1387e41f4b71Sopenharmony_ci
1388e41f4b71Sopenharmony_ci### getOutputDevice<sup>10+</sup>
1389e41f4b71Sopenharmony_ci
1390e41f4b71Sopenharmony_cigetOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
1391e41f4b71Sopenharmony_ci
1392e41f4b71Sopenharmony_ciObtains information about the output device for this session. This API uses an asynchronous callback to return the result.
1393e41f4b71Sopenharmony_ci
1394e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1395e41f4b71Sopenharmony_ci
1396e41f4b71Sopenharmony_ci**Parameters**
1397e41f4b71Sopenharmony_ci
1398e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory| Description                          |
1399e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1400e41f4b71Sopenharmony_ci| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|
1401e41f4b71Sopenharmony_ci
1402e41f4b71Sopenharmony_ci**Error codes**
1403e41f4b71Sopenharmony_ci
1404e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1405e41f4b71Sopenharmony_ci
1406e41f4b71Sopenharmony_ci| ID| Error Message|
1407e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1408e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1409e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1410e41f4b71Sopenharmony_ci
1411e41f4b71Sopenharmony_ci**Example**
1412e41f4b71Sopenharmony_ci
1413e41f4b71Sopenharmony_ci```ts
1414e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1415e41f4b71Sopenharmony_ci
1416e41f4b71Sopenharmony_cicurrentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => {
1417e41f4b71Sopenharmony_ci  if (err) {
1418e41f4b71Sopenharmony_ci    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1419e41f4b71Sopenharmony_ci  } else {
1420e41f4b71Sopenharmony_ci    console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1421e41f4b71Sopenharmony_ci  }
1422e41f4b71Sopenharmony_ci});
1423e41f4b71Sopenharmony_ci```
1424e41f4b71Sopenharmony_ci
1425e41f4b71Sopenharmony_ci### activate<sup>10+</sup>
1426e41f4b71Sopenharmony_ci
1427e41f4b71Sopenharmony_ciactivate(): Promise\<void>
1428e41f4b71Sopenharmony_ci
1429e41f4b71Sopenharmony_ciActivates this session. A session can be used only after being activated. This API uses a promise to return the result.
1430e41f4b71Sopenharmony_ci
1431e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1432e41f4b71Sopenharmony_ci
1433e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1434e41f4b71Sopenharmony_ci
1435e41f4b71Sopenharmony_ci**Return value**
1436e41f4b71Sopenharmony_ci
1437e41f4b71Sopenharmony_ci| Type          | Description                         |
1438e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
1439e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.|
1440e41f4b71Sopenharmony_ci
1441e41f4b71Sopenharmony_ci**Error codes**
1442e41f4b71Sopenharmony_ci
1443e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1444e41f4b71Sopenharmony_ci
1445e41f4b71Sopenharmony_ci| ID| Error Message|
1446e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1447e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1448e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1449e41f4b71Sopenharmony_ci
1450e41f4b71Sopenharmony_ci**Example**
1451e41f4b71Sopenharmony_ci
1452e41f4b71Sopenharmony_ci```ts
1453e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1454e41f4b71Sopenharmony_ci
1455e41f4b71Sopenharmony_cicurrentAVSession.activate().then(() => {
1456e41f4b71Sopenharmony_ci  console.info('Activate : SUCCESS ');
1457e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1458e41f4b71Sopenharmony_ci  console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1459e41f4b71Sopenharmony_ci});
1460e41f4b71Sopenharmony_ci```
1461e41f4b71Sopenharmony_ci
1462e41f4b71Sopenharmony_ci### activate<sup>10+</sup>
1463e41f4b71Sopenharmony_ci
1464e41f4b71Sopenharmony_ciactivate(callback: AsyncCallback\<void>): void
1465e41f4b71Sopenharmony_ci
1466e41f4b71Sopenharmony_ciActivates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result.
1467e41f4b71Sopenharmony_ci
1468e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1469e41f4b71Sopenharmony_ci
1470e41f4b71Sopenharmony_ci**Parameters**
1471e41f4b71Sopenharmony_ci
1472e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description      |
1473e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------- |
1474e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.|
1475e41f4b71Sopenharmony_ci
1476e41f4b71Sopenharmony_ci**Error codes**
1477e41f4b71Sopenharmony_ci
1478e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1479e41f4b71Sopenharmony_ci
1480e41f4b71Sopenharmony_ci| ID| Error Message|
1481e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1482e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1483e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1484e41f4b71Sopenharmony_ci
1485e41f4b71Sopenharmony_ci**Example**
1486e41f4b71Sopenharmony_ci
1487e41f4b71Sopenharmony_ci```ts
1488e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1489e41f4b71Sopenharmony_ci
1490e41f4b71Sopenharmony_cicurrentAVSession.activate((err: BusinessError) => {
1491e41f4b71Sopenharmony_ci  if (err) {
1492e41f4b71Sopenharmony_ci    console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1493e41f4b71Sopenharmony_ci  } else {
1494e41f4b71Sopenharmony_ci    console.info('Activate : SUCCESS ');
1495e41f4b71Sopenharmony_ci  }
1496e41f4b71Sopenharmony_ci});
1497e41f4b71Sopenharmony_ci```
1498e41f4b71Sopenharmony_ci
1499e41f4b71Sopenharmony_ci### deactivate<sup>10+</sup>
1500e41f4b71Sopenharmony_ci
1501e41f4b71Sopenharmony_cideactivate(): Promise\<void>
1502e41f4b71Sopenharmony_ci
1503e41f4b71Sopenharmony_ciDeactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result.
1504e41f4b71Sopenharmony_ci
1505e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1506e41f4b71Sopenharmony_ci
1507e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1508e41f4b71Sopenharmony_ci
1509e41f4b71Sopenharmony_ci**Return value**
1510e41f4b71Sopenharmony_ci
1511e41f4b71Sopenharmony_ci| Type          | Description                         |
1512e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
1513e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.|
1514e41f4b71Sopenharmony_ci
1515e41f4b71Sopenharmony_ci**Error codes**
1516e41f4b71Sopenharmony_ci
1517e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1518e41f4b71Sopenharmony_ci
1519e41f4b71Sopenharmony_ci| ID| Error Message|
1520e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1521e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1522e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1523e41f4b71Sopenharmony_ci
1524e41f4b71Sopenharmony_ci**Example**
1525e41f4b71Sopenharmony_ci
1526e41f4b71Sopenharmony_ci```ts
1527e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1528e41f4b71Sopenharmony_ci
1529e41f4b71Sopenharmony_cicurrentAVSession.deactivate().then(() => {
1530e41f4b71Sopenharmony_ci  console.info('Deactivate : SUCCESS ');
1531e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1532e41f4b71Sopenharmony_ci  console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1533e41f4b71Sopenharmony_ci});
1534e41f4b71Sopenharmony_ci```
1535e41f4b71Sopenharmony_ci
1536e41f4b71Sopenharmony_ci### deactivate<sup>10+</sup>
1537e41f4b71Sopenharmony_ci
1538e41f4b71Sopenharmony_cideactivate(callback: AsyncCallback\<void>): void
1539e41f4b71Sopenharmony_ci
1540e41f4b71Sopenharmony_ciDeactivates this session. This API uses an asynchronous callback to return the result.
1541e41f4b71Sopenharmony_ci
1542e41f4b71Sopenharmony_ciDeactivates this session. You can use [activate](#activate10) to activate the session again.
1543e41f4b71Sopenharmony_ci
1544e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1545e41f4b71Sopenharmony_ci
1546e41f4b71Sopenharmony_ci**Parameters**
1547e41f4b71Sopenharmony_ci
1548e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description      |
1549e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------- |
1550e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.|
1551e41f4b71Sopenharmony_ci
1552e41f4b71Sopenharmony_ci**Error codes**
1553e41f4b71Sopenharmony_ci
1554e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1555e41f4b71Sopenharmony_ci
1556e41f4b71Sopenharmony_ci| ID| Error Message|
1557e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1558e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1559e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1560e41f4b71Sopenharmony_ci
1561e41f4b71Sopenharmony_ci**Example**
1562e41f4b71Sopenharmony_ci
1563e41f4b71Sopenharmony_ci```ts
1564e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1565e41f4b71Sopenharmony_ci
1566e41f4b71Sopenharmony_cicurrentAVSession.deactivate((err: BusinessError) => {
1567e41f4b71Sopenharmony_ci  if (err) {
1568e41f4b71Sopenharmony_ci    console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1569e41f4b71Sopenharmony_ci  } else {
1570e41f4b71Sopenharmony_ci    console.info('Deactivate : SUCCESS ');
1571e41f4b71Sopenharmony_ci  }
1572e41f4b71Sopenharmony_ci});
1573e41f4b71Sopenharmony_ci```
1574e41f4b71Sopenharmony_ci
1575e41f4b71Sopenharmony_ci### destroy<sup>10+</sup>
1576e41f4b71Sopenharmony_ci
1577e41f4b71Sopenharmony_cidestroy(): Promise\<void>
1578e41f4b71Sopenharmony_ci
1579e41f4b71Sopenharmony_ciDestroys this session. This API uses a promise to return the result.
1580e41f4b71Sopenharmony_ci
1581e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1582e41f4b71Sopenharmony_ci
1583e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1584e41f4b71Sopenharmony_ci
1585e41f4b71Sopenharmony_ci**Return value**
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_ci| Type          | Description                         |
1588e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
1589e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.|
1590e41f4b71Sopenharmony_ci
1591e41f4b71Sopenharmony_ci**Error codes**
1592e41f4b71Sopenharmony_ci
1593e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1594e41f4b71Sopenharmony_ci
1595e41f4b71Sopenharmony_ci| ID| Error Message|
1596e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1597e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1598e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1599e41f4b71Sopenharmony_ci
1600e41f4b71Sopenharmony_ci**Example**
1601e41f4b71Sopenharmony_ci
1602e41f4b71Sopenharmony_ci```ts
1603e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1604e41f4b71Sopenharmony_ci
1605e41f4b71Sopenharmony_cicurrentAVSession.destroy().then(() => {
1606e41f4b71Sopenharmony_ci  console.info('Destroy : SUCCESS ');
1607e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
1608e41f4b71Sopenharmony_ci  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1609e41f4b71Sopenharmony_ci});
1610e41f4b71Sopenharmony_ci```
1611e41f4b71Sopenharmony_ci
1612e41f4b71Sopenharmony_ci### destroy<sup>10+</sup>
1613e41f4b71Sopenharmony_ci
1614e41f4b71Sopenharmony_cidestroy(callback: AsyncCallback\<void>): void
1615e41f4b71Sopenharmony_ci
1616e41f4b71Sopenharmony_ciDestroys this session. This API uses an asynchronous callback to return the result.
1617e41f4b71Sopenharmony_ci
1618e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1619e41f4b71Sopenharmony_ci
1620e41f4b71Sopenharmony_ci**Parameters**
1621e41f4b71Sopenharmony_ci
1622e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description      |
1623e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------- |
1624e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
1625e41f4b71Sopenharmony_ci
1626e41f4b71Sopenharmony_ci**Error codes**
1627e41f4b71Sopenharmony_ci
1628e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1629e41f4b71Sopenharmony_ci
1630e41f4b71Sopenharmony_ci| ID| Error Message|
1631e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1632e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1633e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1634e41f4b71Sopenharmony_ci
1635e41f4b71Sopenharmony_ci**Example**
1636e41f4b71Sopenharmony_ci
1637e41f4b71Sopenharmony_ci```ts
1638e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1639e41f4b71Sopenharmony_ci
1640e41f4b71Sopenharmony_cicurrentAVSession.destroy((err: BusinessError) => {
1641e41f4b71Sopenharmony_ci  if (err) {
1642e41f4b71Sopenharmony_ci    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1643e41f4b71Sopenharmony_ci  } else {
1644e41f4b71Sopenharmony_ci    console.info('Destroy : SUCCESS ');
1645e41f4b71Sopenharmony_ci  }
1646e41f4b71Sopenharmony_ci});
1647e41f4b71Sopenharmony_ci```
1648e41f4b71Sopenharmony_ci
1649e41f4b71Sopenharmony_ci### on('play')<sup>10+</sup>
1650e41f4b71Sopenharmony_ci
1651e41f4b71Sopenharmony_cion(type: 'play', callback: () => void): void
1652e41f4b71Sopenharmony_ci
1653e41f4b71Sopenharmony_ciSubscribes to play command events. The subscription means that the application supports the play command.
1654e41f4b71Sopenharmony_ci
1655e41f4b71Sopenharmony_ciOnly one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1656e41f4b71Sopenharmony_ci
1657e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1658e41f4b71Sopenharmony_ci
1659e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1660e41f4b71Sopenharmony_ci
1661e41f4b71Sopenharmony_ci**Parameters**
1662e41f4b71Sopenharmony_ci
1663e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1664e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1665e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.|
1666e41f4b71Sopenharmony_ci| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                                       |
1667e41f4b71Sopenharmony_ci
1668e41f4b71Sopenharmony_ci**Error codes**
1669e41f4b71Sopenharmony_ci
1670e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1671e41f4b71Sopenharmony_ci
1672e41f4b71Sopenharmony_ci| ID| Error Message|
1673e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1674e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1675e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1676e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1677e41f4b71Sopenharmony_ci
1678e41f4b71Sopenharmony_ci**Example**
1679e41f4b71Sopenharmony_ci
1680e41f4b71Sopenharmony_ci```ts
1681e41f4b71Sopenharmony_cicurrentAVSession.on('play', () => {
1682e41f4b71Sopenharmony_ci  console.info('on play entry');
1683e41f4b71Sopenharmony_ci});
1684e41f4b71Sopenharmony_ci```
1685e41f4b71Sopenharmony_ci
1686e41f4b71Sopenharmony_ci### on('pause')<sup>10+</sup>
1687e41f4b71Sopenharmony_ci
1688e41f4b71Sopenharmony_cion(type: 'pause', callback: () => void): void
1689e41f4b71Sopenharmony_ci
1690e41f4b71Sopenharmony_ciSubscribes to pause command events. The subscription means that the application supports the pause command.
1691e41f4b71Sopenharmony_ci
1692e41f4b71Sopenharmony_ciOnly one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1693e41f4b71Sopenharmony_ci
1694e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1695e41f4b71Sopenharmony_ci
1696e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1697e41f4b71Sopenharmony_ci
1698e41f4b71Sopenharmony_ci**Parameters**
1699e41f4b71Sopenharmony_ci
1700e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1701e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1702e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.|
1703e41f4b71Sopenharmony_ci| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |
1704e41f4b71Sopenharmony_ci
1705e41f4b71Sopenharmony_ci**Error codes**
1706e41f4b71Sopenharmony_ci
1707e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1708e41f4b71Sopenharmony_ci
1709e41f4b71Sopenharmony_ci| ID| Error Message|
1710e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1711e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1712e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1713e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1714e41f4b71Sopenharmony_ci
1715e41f4b71Sopenharmony_ci**Example**
1716e41f4b71Sopenharmony_ci
1717e41f4b71Sopenharmony_ci```ts
1718e41f4b71Sopenharmony_cicurrentAVSession.on('pause', () => {
1719e41f4b71Sopenharmony_ci  console.info('on pause entry');
1720e41f4b71Sopenharmony_ci});
1721e41f4b71Sopenharmony_ci```
1722e41f4b71Sopenharmony_ci
1723e41f4b71Sopenharmony_ci### on('stop')<sup>10+</sup>
1724e41f4b71Sopenharmony_ci
1725e41f4b71Sopenharmony_cion(type:'stop', callback: () => void): void
1726e41f4b71Sopenharmony_ci
1727e41f4b71Sopenharmony_ciSubscribes to stop command events. The subscription means that the application supports the stop command.
1728e41f4b71Sopenharmony_ci
1729e41f4b71Sopenharmony_ciOnly one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1730e41f4b71Sopenharmony_ci
1731e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1732e41f4b71Sopenharmony_ci
1733e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1734e41f4b71Sopenharmony_ci
1735e41f4b71Sopenharmony_ci**Parameters**
1736e41f4b71Sopenharmony_ci
1737e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1738e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1739e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.|
1740e41f4b71Sopenharmony_ci| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
1741e41f4b71Sopenharmony_ci
1742e41f4b71Sopenharmony_ci**Error codes**
1743e41f4b71Sopenharmony_ci
1744e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1745e41f4b71Sopenharmony_ci
1746e41f4b71Sopenharmony_ci| ID| Error Message|
1747e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1748e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1749e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1750e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1751e41f4b71Sopenharmony_ci
1752e41f4b71Sopenharmony_ci**Example**
1753e41f4b71Sopenharmony_ci
1754e41f4b71Sopenharmony_ci```ts
1755e41f4b71Sopenharmony_cicurrentAVSession.on('stop', () => {
1756e41f4b71Sopenharmony_ci  console.info('on stop entry');
1757e41f4b71Sopenharmony_ci});
1758e41f4b71Sopenharmony_ci```
1759e41f4b71Sopenharmony_ci
1760e41f4b71Sopenharmony_ci### on('playNext')<sup>10+</sup>
1761e41f4b71Sopenharmony_ci
1762e41f4b71Sopenharmony_cion(type:'playNext', callback: () => void): void
1763e41f4b71Sopenharmony_ci
1764e41f4b71Sopenharmony_ciSubscribes to playNext command events. The subscription means that the application supports the playNext command.
1765e41f4b71Sopenharmony_ci
1766e41f4b71Sopenharmony_ciOnly one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1767e41f4b71Sopenharmony_ci
1768e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1769e41f4b71Sopenharmony_ci
1770e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1771e41f4b71Sopenharmony_ci
1772e41f4b71Sopenharmony_ci**Parameters**
1773e41f4b71Sopenharmony_ci
1774e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1775e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1776e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.|
1777e41f4b71Sopenharmony_ci| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |
1778e41f4b71Sopenharmony_ci
1779e41f4b71Sopenharmony_ci**Error codes**
1780e41f4b71Sopenharmony_ci
1781e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1782e41f4b71Sopenharmony_ci
1783e41f4b71Sopenharmony_ci| ID| Error Message|
1784e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1785e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1786e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1787e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1788e41f4b71Sopenharmony_ci
1789e41f4b71Sopenharmony_ci**Example**
1790e41f4b71Sopenharmony_ci
1791e41f4b71Sopenharmony_ci```ts
1792e41f4b71Sopenharmony_cicurrentAVSession.on('playNext', () => {
1793e41f4b71Sopenharmony_ci  console.info('on playNext entry');
1794e41f4b71Sopenharmony_ci});
1795e41f4b71Sopenharmony_ci```
1796e41f4b71Sopenharmony_ci
1797e41f4b71Sopenharmony_ci### on('playPrevious')<sup>10+</sup>
1798e41f4b71Sopenharmony_ci
1799e41f4b71Sopenharmony_cion(type:'playPrevious', callback: () => void): void
1800e41f4b71Sopenharmony_ci
1801e41f4b71Sopenharmony_ciSubscribes to playPrevious command events. The subscription means that the application supports the playPrevious command.
1802e41f4b71Sopenharmony_ci
1803e41f4b71Sopenharmony_ciOnly one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1804e41f4b71Sopenharmony_ci
1805e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1808e41f4b71Sopenharmony_ci
1809e41f4b71Sopenharmony_ci**Parameters**
1810e41f4b71Sopenharmony_ci
1811e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1812e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1813e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.|
1814e41f4b71Sopenharmony_ci| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.      |
1815e41f4b71Sopenharmony_ci
1816e41f4b71Sopenharmony_ci**Error codes**
1817e41f4b71Sopenharmony_ci
1818e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1819e41f4b71Sopenharmony_ci
1820e41f4b71Sopenharmony_ci| ID| Error Message|
1821e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1822e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1823e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1824e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1825e41f4b71Sopenharmony_ci
1826e41f4b71Sopenharmony_ci**Example**
1827e41f4b71Sopenharmony_ci
1828e41f4b71Sopenharmony_ci```ts
1829e41f4b71Sopenharmony_cicurrentAVSession.on('playPrevious', () => {
1830e41f4b71Sopenharmony_ci  console.info('on playPrevious entry');
1831e41f4b71Sopenharmony_ci});
1832e41f4b71Sopenharmony_ci```
1833e41f4b71Sopenharmony_ci
1834e41f4b71Sopenharmony_ci### on('fastForward')<sup>10+</sup>
1835e41f4b71Sopenharmony_ci
1836e41f4b71Sopenharmony_cion(type: 'fastForward', callback: (time?: number) => void): void
1837e41f4b71Sopenharmony_ci
1838e41f4b71Sopenharmony_ciSubscribes to fastForward command events. The subscription means that the application supports the fastForward command.
1839e41f4b71Sopenharmony_ci
1840e41f4b71Sopenharmony_ciOnly one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1841e41f4b71Sopenharmony_ci
1842e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1843e41f4b71Sopenharmony_ci
1844e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1845e41f4b71Sopenharmony_ci
1846e41f4b71Sopenharmony_ci**Parameters**
1847e41f4b71Sopenharmony_ci
1848e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1849e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1850e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.|
1851e41f4b71Sopenharmony_ci| callback | (time?: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds.   |
1852e41f4b71Sopenharmony_ci
1853e41f4b71Sopenharmony_ci**Error codes**
1854e41f4b71Sopenharmony_ci
1855e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1856e41f4b71Sopenharmony_ci
1857e41f4b71Sopenharmony_ci| ID| Error Message|
1858e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1859e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1860e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1861e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1862e41f4b71Sopenharmony_ci
1863e41f4b71Sopenharmony_ci**Example**
1864e41f4b71Sopenharmony_ci
1865e41f4b71Sopenharmony_ci```ts
1866e41f4b71Sopenharmony_cicurrentAVSession.on('fastForward', (time?: number) => {
1867e41f4b71Sopenharmony_ci  console.info('on fastForward entry');
1868e41f4b71Sopenharmony_ci});
1869e41f4b71Sopenharmony_ci```
1870e41f4b71Sopenharmony_ci
1871e41f4b71Sopenharmony_ci### on('rewind')<sup>10+</sup>
1872e41f4b71Sopenharmony_ci
1873e41f4b71Sopenharmony_cion(type:'rewind', callback: (time?: number) => void): void
1874e41f4b71Sopenharmony_ci
1875e41f4b71Sopenharmony_ciSubscribes to rewind command events.
1876e41f4b71Sopenharmony_ci
1877e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1878e41f4b71Sopenharmony_ci
1879e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1880e41f4b71Sopenharmony_ci
1881e41f4b71Sopenharmony_ci**Parameters**
1882e41f4b71Sopenharmony_ci
1883e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1884e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1885e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.|
1886e41f4b71Sopenharmony_ci| callback | (time?: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds.     |
1887e41f4b71Sopenharmony_ci
1888e41f4b71Sopenharmony_ci**Error codes**
1889e41f4b71Sopenharmony_ci
1890e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1891e41f4b71Sopenharmony_ci
1892e41f4b71Sopenharmony_ci| ID| Error Message|
1893e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1894e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1895e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1896e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1897e41f4b71Sopenharmony_ci
1898e41f4b71Sopenharmony_ci**Example**
1899e41f4b71Sopenharmony_ci
1900e41f4b71Sopenharmony_ci```ts
1901e41f4b71Sopenharmony_cicurrentAVSession.on('rewind', (time?: number) => {
1902e41f4b71Sopenharmony_ci  console.info('on rewind entry');
1903e41f4b71Sopenharmony_ci});
1904e41f4b71Sopenharmony_ci```
1905e41f4b71Sopenharmony_ci
1906e41f4b71Sopenharmony_ci### on('playFromAssetId')<sup>11+</sup>
1907e41f4b71Sopenharmony_ci
1908e41f4b71Sopenharmony_cion(type:'playFromAssetId', callback: (assetId: number) => void): void
1909e41f4b71Sopenharmony_ci
1910e41f4b71Sopenharmony_ciSubscribes to playback events of a given media ID.
1911e41f4b71Sopenharmony_ci
1912e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1913e41f4b71Sopenharmony_ci
1914e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1915e41f4b71Sopenharmony_ci
1916e41f4b71Sopenharmony_ci**Parameters**
1917e41f4b71Sopenharmony_ci
1918e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                                        |
1919e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1920e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type. The event **'playFromAssetId'** is triggered when the media ID is played.|
1921e41f4b71Sopenharmony_ci| callback | callback: (assetId: number) => void | Yes  | Callback The **assetId** parameter in the callback indicates the media asset ID.     |
1922e41f4b71Sopenharmony_ci
1923e41f4b71Sopenharmony_ci**Error codes**
1924e41f4b71Sopenharmony_ci
1925e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1926e41f4b71Sopenharmony_ci
1927e41f4b71Sopenharmony_ci| ID| Error Message|
1928e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1929e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1930e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1931e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1932e41f4b71Sopenharmony_ci
1933e41f4b71Sopenharmony_ci**Example**
1934e41f4b71Sopenharmony_ci
1935e41f4b71Sopenharmony_ci```ts
1936e41f4b71Sopenharmony_cicurrentAVSession.on('playFromAssetId', (assetId: number) => {
1937e41f4b71Sopenharmony_ci  console.info('on playFromAssetId entry');
1938e41f4b71Sopenharmony_ci});
1939e41f4b71Sopenharmony_ci```
1940e41f4b71Sopenharmony_ci
1941e41f4b71Sopenharmony_ci### off('playFromAssetId')<sup>11+</sup>
1942e41f4b71Sopenharmony_ci
1943e41f4b71Sopenharmony_cioff(type: 'playFromAssetId', callback?: (assetId: number) => void): void
1944e41f4b71Sopenharmony_ci
1945e41f4b71Sopenharmony_ciUnsubscribes from playback events of a given media ID.
1946e41f4b71Sopenharmony_ci
1947e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1948e41f4b71Sopenharmony_ci
1949e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1950e41f4b71Sopenharmony_ci
1951e41f4b71Sopenharmony_ci**Parameters**
1952e41f4b71Sopenharmony_ci
1953e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
1954e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
1955e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'playFromAssetId'** in this case.|
1956e41f4b71Sopenharmony_ci| callback | callback: (assetId: number) => 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. The **assetId** parameter in the callback indicates the media asset ID.                           |
1957e41f4b71Sopenharmony_ci
1958e41f4b71Sopenharmony_ci**Error codes**
1959e41f4b71Sopenharmony_ci
1960e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1961e41f4b71Sopenharmony_ci
1962e41f4b71Sopenharmony_ci| ID| Error Message|
1963e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1964e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1965e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1966e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
1967e41f4b71Sopenharmony_ci
1968e41f4b71Sopenharmony_ci**Example**
1969e41f4b71Sopenharmony_ci
1970e41f4b71Sopenharmony_ci```ts
1971e41f4b71Sopenharmony_cicurrentAVSession.off('playFromAssetId');
1972e41f4b71Sopenharmony_ci```
1973e41f4b71Sopenharmony_ci
1974e41f4b71Sopenharmony_ci### on('seek')<sup>10+</sup>
1975e41f4b71Sopenharmony_ci
1976e41f4b71Sopenharmony_cion(type: 'seek', callback: (time: number) => void): void
1977e41f4b71Sopenharmony_ci
1978e41f4b71Sopenharmony_ciSubscribes to seek command events.
1979e41f4b71Sopenharmony_ci
1980e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1981e41f4b71Sopenharmony_ci
1982e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
1983e41f4b71Sopenharmony_ci
1984e41f4b71Sopenharmony_ci**Parameters**
1985e41f4b71Sopenharmony_ci
1986e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                                        |
1987e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1988e41f4b71Sopenharmony_ci| type     | string                 | Yes  | Event type. The event **'seek'** is triggered when the seek command is sent to the session.|
1989e41f4b71Sopenharmony_ci| callback | (time: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.                  |
1990e41f4b71Sopenharmony_ci
1991e41f4b71Sopenharmony_ci**Error codes**
1992e41f4b71Sopenharmony_ci
1993e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1994e41f4b71Sopenharmony_ci
1995e41f4b71Sopenharmony_ci| ID| Error Message|
1996e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
1997e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1998e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
1999e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2000e41f4b71Sopenharmony_ci
2001e41f4b71Sopenharmony_ci**Example**
2002e41f4b71Sopenharmony_ci
2003e41f4b71Sopenharmony_ci```ts
2004e41f4b71Sopenharmony_cicurrentAVSession.on('seek', (time: number) => {
2005e41f4b71Sopenharmony_ci  console.info(`on seek entry time : ${time}`);
2006e41f4b71Sopenharmony_ci});
2007e41f4b71Sopenharmony_ci```
2008e41f4b71Sopenharmony_ci
2009e41f4b71Sopenharmony_ci### on('setSpeed')<sup>10+</sup>
2010e41f4b71Sopenharmony_ci
2011e41f4b71Sopenharmony_cion(type: 'setSpeed', callback: (speed: number) => void): void
2012e41f4b71Sopenharmony_ci
2013e41f4b71Sopenharmony_ciSubscribes to setSpeed command events.
2014e41f4b71Sopenharmony_ci
2015e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2016e41f4b71Sopenharmony_ci
2017e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2018e41f4b71Sopenharmony_ci
2019e41f4b71Sopenharmony_ci**Parameters**
2020e41f4b71Sopenharmony_ci
2021e41f4b71Sopenharmony_ci| Name  | Type                   | Mandatory| Description                                                        |
2022e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
2023e41f4b71Sopenharmony_ci| type     | string                  | Yes  | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.|
2024e41f4b71Sopenharmony_ci| callback | (speed: number) => void | Yes  | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed.                             |
2025e41f4b71Sopenharmony_ci
2026e41f4b71Sopenharmony_ci**Error codes**
2027e41f4b71Sopenharmony_ci
2028e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2029e41f4b71Sopenharmony_ci
2030e41f4b71Sopenharmony_ci| ID| Error Message|
2031e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2032e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2033e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2034e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2035e41f4b71Sopenharmony_ci
2036e41f4b71Sopenharmony_ci**Example**
2037e41f4b71Sopenharmony_ci
2038e41f4b71Sopenharmony_ci```ts
2039e41f4b71Sopenharmony_cicurrentAVSession.on('setSpeed', (speed: number) => {
2040e41f4b71Sopenharmony_ci  console.info(`on setSpeed speed : ${speed}`);
2041e41f4b71Sopenharmony_ci});
2042e41f4b71Sopenharmony_ci```
2043e41f4b71Sopenharmony_ci
2044e41f4b71Sopenharmony_ci### on('setLoopMode')<sup>10+</sup>
2045e41f4b71Sopenharmony_ci
2046e41f4b71Sopenharmony_cion(type: 'setLoopMode', callback: (mode: LoopMode) => void): void
2047e41f4b71Sopenharmony_ci
2048e41f4b71Sopenharmony_ciSubscribes to setLoopMode command events.
2049e41f4b71Sopenharmony_ci
2050e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2051e41f4b71Sopenharmony_ci
2052e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2053e41f4b71Sopenharmony_ci
2054e41f4b71Sopenharmony_ci**Parameters**
2055e41f4b71Sopenharmony_ci
2056e41f4b71Sopenharmony_ci| Name   | Type                                  | Mandatory| Description |
2057e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ---- |
2058e41f4b71Sopenharmony_ci| type     | string                                | Yes  | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.|
2059e41f4b71Sopenharmony_ci| callback | (mode: [LoopMode](#loopmode10)) => void | Yes  | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode.                              |
2060e41f4b71Sopenharmony_ci
2061e41f4b71Sopenharmony_ci**Error codes**
2062e41f4b71Sopenharmony_ci
2063e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2064e41f4b71Sopenharmony_ci
2065e41f4b71Sopenharmony_ci| ID| Error Message|
2066e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2067e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2068e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2069e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2070e41f4b71Sopenharmony_ci
2071e41f4b71Sopenharmony_ci**Example**
2072e41f4b71Sopenharmony_ci
2073e41f4b71Sopenharmony_ci```ts
2074e41f4b71Sopenharmony_cicurrentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => {
2075e41f4b71Sopenharmony_ci  console.info(`on setLoopMode mode : ${mode}`);
2076e41f4b71Sopenharmony_ci});
2077e41f4b71Sopenharmony_ci```
2078e41f4b71Sopenharmony_ci
2079e41f4b71Sopenharmony_ci### on('toggleFavorite')<sup>10+</sup>
2080e41f4b71Sopenharmony_ci
2081e41f4b71Sopenharmony_cion(type: 'toggleFavorite', callback: (assetId: string) => void): void
2082e41f4b71Sopenharmony_ci
2083e41f4b71Sopenharmony_ciSubscribes to toggleFavorite command events.
2084e41f4b71Sopenharmony_ci
2085e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2086e41f4b71Sopenharmony_ci
2087e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2088e41f4b71Sopenharmony_ci
2089e41f4b71Sopenharmony_ci**Parameters**
2090e41f4b71Sopenharmony_ci
2091e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                                        |
2092e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
2093e41f4b71Sopenharmony_ci| type     | string                    | Yes  | Event type. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.|
2094e41f4b71Sopenharmony_ci| callback | (assetId: string) => void | Yes  | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID.                             |
2095e41f4b71Sopenharmony_ci
2096e41f4b71Sopenharmony_ci**Error codes**
2097e41f4b71Sopenharmony_ci
2098e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2099e41f4b71Sopenharmony_ci
2100e41f4b71Sopenharmony_ci| ID| Error Message|
2101e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2102e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2103e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2104e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2105e41f4b71Sopenharmony_ci
2106e41f4b71Sopenharmony_ci**Example**
2107e41f4b71Sopenharmony_ci
2108e41f4b71Sopenharmony_ci```ts
2109e41f4b71Sopenharmony_cicurrentAVSession.on('toggleFavorite', (assetId: string) => {
2110e41f4b71Sopenharmony_ci  console.info(`on toggleFavorite mode : ${assetId}`);
2111e41f4b71Sopenharmony_ci});
2112e41f4b71Sopenharmony_ci```
2113e41f4b71Sopenharmony_ci
2114e41f4b71Sopenharmony_ci### on('skipToQueueItem')<sup>10+</sup>
2115e41f4b71Sopenharmony_ci
2116e41f4b71Sopenharmony_cion(type: 'skipToQueueItem', callback: (itemId: number) => void): void
2117e41f4b71Sopenharmony_ci
2118e41f4b71Sopenharmony_ciSubscribes to the event that indicates an item in the playlist is selected. The session can play the selected item.
2119e41f4b71Sopenharmony_ci
2120e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2121e41f4b71Sopenharmony_ci
2122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2123e41f4b71Sopenharmony_ci
2124e41f4b71Sopenharmony_ci**Parameters**
2125e41f4b71Sopenharmony_ci
2126e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                                                                     |
2127e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- |
2128e41f4b71Sopenharmony_ci| type     | string                   | Yes  | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.|
2129e41f4b71Sopenharmony_ci| callback | (itemId: number) => void | Yes  | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item.                                               |
2130e41f4b71Sopenharmony_ci
2131e41f4b71Sopenharmony_ci**Error codes**
2132e41f4b71Sopenharmony_ci
2133e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2134e41f4b71Sopenharmony_ci
2135e41f4b71Sopenharmony_ci| ID| Error Message|
2136e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2137e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2138e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2139e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2140e41f4b71Sopenharmony_ci
2141e41f4b71Sopenharmony_ci**Example**
2142e41f4b71Sopenharmony_ci
2143e41f4b71Sopenharmony_ci```ts
2144e41f4b71Sopenharmony_cicurrentAVSession.on('skipToQueueItem', (itemId: number) => {
2145e41f4b71Sopenharmony_ci  console.info(`on skipToQueueItem id : ${itemId}`);
2146e41f4b71Sopenharmony_ci});
2147e41f4b71Sopenharmony_ci```
2148e41f4b71Sopenharmony_ci
2149e41f4b71Sopenharmony_ci### on('handleKeyEvent')<sup>10+</sup>
2150e41f4b71Sopenharmony_ci
2151e41f4b71Sopenharmony_cion(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void
2152e41f4b71Sopenharmony_ci
2153e41f4b71Sopenharmony_ciSubscribes to key events of external devices such as Bluetooth and wired devices to listen for the play, pause, previous, next, fast-forward, and rewind commands in the key events.
2154e41f4b71Sopenharmony_ci
2155e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2156e41f4b71Sopenharmony_ci
2157e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2158e41f4b71Sopenharmony_ci
2159e41f4b71Sopenharmony_ci**Parameters**
2160e41f4b71Sopenharmony_ci
2161e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
2162e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2163e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.|
2164e41f4b71Sopenharmony_ci| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | Yes  | Callback used for subscription. The **event** parameter in the callback indicates the key event.                             |
2165e41f4b71Sopenharmony_ci
2166e41f4b71Sopenharmony_ci**Error codes**
2167e41f4b71Sopenharmony_ci
2168e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2169e41f4b71Sopenharmony_ci
2170e41f4b71Sopenharmony_ci| ID| Error Message|
2171e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2172e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2173e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2174e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2175e41f4b71Sopenharmony_ci
2176e41f4b71Sopenharmony_ci**Example**
2177e41f4b71Sopenharmony_ci
2178e41f4b71Sopenharmony_ci```ts
2179e41f4b71Sopenharmony_ciimport { KeyEvent } from '@kit.InputKit';
2180e41f4b71Sopenharmony_ci
2181e41f4b71Sopenharmony_cicurrentAVSession.on('handleKeyEvent', (event: KeyEvent) => {
2182e41f4b71Sopenharmony_ci  console.info(`on handleKeyEvent event : ${event}`);
2183e41f4b71Sopenharmony_ci});
2184e41f4b71Sopenharmony_ci
2185e41f4b71Sopenharmony_ci```
2186e41f4b71Sopenharmony_ci
2187e41f4b71Sopenharmony_ci### on('outputDeviceChange')<sup>10+</sup>
2188e41f4b71Sopenharmony_ci
2189e41f4b71Sopenharmony_cion(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2190e41f4b71Sopenharmony_ci
2191e41f4b71Sopenharmony_ciSubscribes to output device change events. After the application integrates the [**AVCastPicker** component](ohos-multimedia-avcastpicker.md), the application receives the device change callback when the user switches the device through the component.
2192e41f4b71Sopenharmony_ci
2193e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2194e41f4b71Sopenharmony_ci
2195e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2196e41f4b71Sopenharmony_ci
2197e41f4b71Sopenharmony_ci**Parameters**
2198e41f4b71Sopenharmony_ci
2199e41f4b71Sopenharmony_ci| Name  | Type                                                   | Mandatory| Description                                                        |
2200e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2201e41f4b71Sopenharmony_ci| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
2202e41f4b71Sopenharmony_ci| 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.                        |
2203e41f4b71Sopenharmony_ci
2204e41f4b71Sopenharmony_ci**Error codes**
2205e41f4b71Sopenharmony_ci
2206e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2207e41f4b71Sopenharmony_ci
2208e41f4b71Sopenharmony_ci| ID| Error Message|
2209e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2210e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2211e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2212e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2213e41f4b71Sopenharmony_ci
2214e41f4b71Sopenharmony_ci**Example**
2215e41f4b71Sopenharmony_ci
2216e41f4b71Sopenharmony_ci```ts
2217e41f4b71Sopenharmony_cicurrentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
2218e41f4b71Sopenharmony_ci  console.info(`on outputDeviceChange device : ${device}`);
2219e41f4b71Sopenharmony_ci});
2220e41f4b71Sopenharmony_ci```
2221e41f4b71Sopenharmony_ci
2222e41f4b71Sopenharmony_ci### on('commonCommand')<sup>10+</sup>
2223e41f4b71Sopenharmony_ci
2224e41f4b71Sopenharmony_cion(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void
2225e41f4b71Sopenharmony_ci
2226e41f4b71Sopenharmony_ciSubscribes to custom control command change events.
2227e41f4b71Sopenharmony_ci
2228e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2229e41f4b71Sopenharmony_ci
2230e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2231e41f4b71Sopenharmony_ci
2232e41f4b71Sopenharmony_ci**Parameters**
2233e41f4b71Sopenharmony_ci
2234e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
2235e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2236e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The event **'commonCommand'** is triggered when a custom control command changes.|
2237e41f4b71Sopenharmony_ci| callback | (command: string, args: {[key:string]: Object}) => void         | Yes  | Callback used for subscription. The **command** 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 [sendCommonCommand](#sendcommoncommand10).         |
2238e41f4b71Sopenharmony_ci
2239e41f4b71Sopenharmony_ci**Error codes**
2240e41f4b71Sopenharmony_ci
2241e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2242e41f4b71Sopenharmony_ci
2243e41f4b71Sopenharmony_ci| ID| Error Message|
2244e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
2245e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2246e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2247e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2248e41f4b71Sopenharmony_ci
2249e41f4b71Sopenharmony_ci**Example**
2250e41f4b71Sopenharmony_ci
2251e41f4b71Sopenharmony_ci```ts
2252e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
2253e41f4b71Sopenharmony_ci
2254e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
2255e41f4b71Sopenharmony_cilet tag = "createNewSession";
2256e41f4b71Sopenharmony_cilet context: Context = getContext(this);
2257e41f4b71Sopenharmony_ci
2258e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
2259e41f4b71Sopenharmony_ci  if (err) {
2260e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
2261e41f4b71Sopenharmony_ci  } else {
2262e41f4b71Sopenharmony_ci    currentAVSession = data;
2263e41f4b71Sopenharmony_ci  }
2264e41f4b71Sopenharmony_ci});
2265e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
2266e41f4b71Sopenharmony_ci  (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => {
2267e41f4b71Sopenharmony_ci    console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
2268e41f4b71Sopenharmony_ci  });
2269e41f4b71Sopenharmony_ci}
2270e41f4b71Sopenharmony_ci```
2271e41f4b71Sopenharmony_ci
2272e41f4b71Sopenharmony_ci### off('play')<sup>10+</sup>
2273e41f4b71Sopenharmony_ci
2274e41f4b71Sopenharmony_cioff(type: 'play', callback?: () => void): void
2275e41f4b71Sopenharmony_ci
2276e41f4b71Sopenharmony_ciUnsubscribes from play command events.
2277e41f4b71Sopenharmony_ci
2278e41f4b71Sopenharmony_ciAfter the callback is canceled, the list of supported commands must be updated.
2279e41f4b71Sopenharmony_ci
2280e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2281e41f4b71Sopenharmony_ci
2282e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2283e41f4b71Sopenharmony_ci
2284e41f4b71Sopenharmony_ci**Parameters**
2285e41f4b71Sopenharmony_ci
2286e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2287e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2288e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'play'** in this case.|
2289e41f4b71Sopenharmony_ci| 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.                           |
2290e41f4b71Sopenharmony_ci
2291e41f4b71Sopenharmony_ci**Error codes**
2292e41f4b71Sopenharmony_ci
2293e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2294e41f4b71Sopenharmony_ci
2295e41f4b71Sopenharmony_ci| ID| Error Message|
2296e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2297e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2298e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2299e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2300e41f4b71Sopenharmony_ci
2301e41f4b71Sopenharmony_ci**Example**
2302e41f4b71Sopenharmony_ci
2303e41f4b71Sopenharmony_ci```ts
2304e41f4b71Sopenharmony_cicurrentAVSession.off('play');
2305e41f4b71Sopenharmony_ci```
2306e41f4b71Sopenharmony_ci
2307e41f4b71Sopenharmony_ci### off('pause')<sup>10+</sup>
2308e41f4b71Sopenharmony_ci
2309e41f4b71Sopenharmony_cioff(type: 'pause', callback?: () => void): void
2310e41f4b71Sopenharmony_ci
2311e41f4b71Sopenharmony_ciUnsubscribes from pause command events.
2312e41f4b71Sopenharmony_ci
2313e41f4b71Sopenharmony_ciAfter the callback is canceled, the list of supported commands must be updated.
2314e41f4b71Sopenharmony_ci
2315e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2316e41f4b71Sopenharmony_ci
2317e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2318e41f4b71Sopenharmony_ci
2319e41f4b71Sopenharmony_ci**Parameters**
2320e41f4b71Sopenharmony_ci
2321e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2322e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2323e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'pause'** in this case.|
2324e41f4b71Sopenharmony_ci| 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.|
2325e41f4b71Sopenharmony_ci
2326e41f4b71Sopenharmony_ci**Error codes**
2327e41f4b71Sopenharmony_ci
2328e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2329e41f4b71Sopenharmony_ci
2330e41f4b71Sopenharmony_ci| ID| Error Message|
2331e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2332e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2333e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2334e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2335e41f4b71Sopenharmony_ci
2336e41f4b71Sopenharmony_ci**Example**
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ci```ts
2339e41f4b71Sopenharmony_cicurrentAVSession.off('pause');
2340e41f4b71Sopenharmony_ci```
2341e41f4b71Sopenharmony_ci
2342e41f4b71Sopenharmony_ci### off('stop')<sup>10+</sup>
2343e41f4b71Sopenharmony_ci
2344e41f4b71Sopenharmony_cioff(type: 'stop', callback?: () => void): void
2345e41f4b71Sopenharmony_ci
2346e41f4b71Sopenharmony_ciUnsubscribes from stop command events.
2347e41f4b71Sopenharmony_ci
2348e41f4b71Sopenharmony_ciAfter the callback is canceled, the list of supported commands must be updated.
2349e41f4b71Sopenharmony_ci
2350e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2351e41f4b71Sopenharmony_ci
2352e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2353e41f4b71Sopenharmony_ci
2354e41f4b71Sopenharmony_ci**Parameters**
2355e41f4b71Sopenharmony_ci
2356e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2357e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2358e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'stop'** in this case.|
2359e41f4b71Sopenharmony_ci| 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.                           |
2360e41f4b71Sopenharmony_ci
2361e41f4b71Sopenharmony_ci**Error codes**
2362e41f4b71Sopenharmony_ci
2363e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2364e41f4b71Sopenharmony_ci
2365e41f4b71Sopenharmony_ci| ID| Error Message|
2366e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2367e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2368e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2369e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2370e41f4b71Sopenharmony_ci
2371e41f4b71Sopenharmony_ci**Example**
2372e41f4b71Sopenharmony_ci
2373e41f4b71Sopenharmony_ci```ts
2374e41f4b71Sopenharmony_cicurrentAVSession.off('stop');
2375e41f4b71Sopenharmony_ci```
2376e41f4b71Sopenharmony_ci
2377e41f4b71Sopenharmony_ci### off('playNext')<sup>10+</sup>
2378e41f4b71Sopenharmony_ci
2379e41f4b71Sopenharmony_cioff(type: 'playNext', callback?: () => void): void
2380e41f4b71Sopenharmony_ci
2381e41f4b71Sopenharmony_ciUnsubscribes from playNext command events.
2382e41f4b71Sopenharmony_ci
2383e41f4b71Sopenharmony_ciAfter the callback is canceled, the list of supported commands must be updated.
2384e41f4b71Sopenharmony_ci
2385e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2386e41f4b71Sopenharmony_ci
2387e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2388e41f4b71Sopenharmony_ci
2389e41f4b71Sopenharmony_ci**Parameters**
2390e41f4b71Sopenharmony_ci
2391e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2392e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2393e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'playNext'** in this case.|
2394e41f4b71Sopenharmony_ci| 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.                           |
2395e41f4b71Sopenharmony_ci
2396e41f4b71Sopenharmony_ci**Error codes**
2397e41f4b71Sopenharmony_ci
2398e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2399e41f4b71Sopenharmony_ci
2400e41f4b71Sopenharmony_ci| ID| Error Message|
2401e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2402e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2403e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2404e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2405e41f4b71Sopenharmony_ci
2406e41f4b71Sopenharmony_ci**Example**
2407e41f4b71Sopenharmony_ci
2408e41f4b71Sopenharmony_ci```ts
2409e41f4b71Sopenharmony_cicurrentAVSession.off('playNext');
2410e41f4b71Sopenharmony_ci```
2411e41f4b71Sopenharmony_ci
2412e41f4b71Sopenharmony_ci### off('playPrevious')<sup>10+</sup>
2413e41f4b71Sopenharmony_ci
2414e41f4b71Sopenharmony_cioff(type: 'playPrevious', callback?: () => void): void
2415e41f4b71Sopenharmony_ci
2416e41f4b71Sopenharmony_ciUnsubscribes from playPrevious command events.
2417e41f4b71Sopenharmony_ci
2418e41f4b71Sopenharmony_ciAfter the callback is canceled, the list of supported commands must be updated.
2419e41f4b71Sopenharmony_ci
2420e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2421e41f4b71Sopenharmony_ci
2422e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2423e41f4b71Sopenharmony_ci
2424e41f4b71Sopenharmony_ci**Parameters**
2425e41f4b71Sopenharmony_ci
2426e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2427e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2428e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'playPrevious'** in this case.|
2429e41f4b71Sopenharmony_ci| 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.                           |
2430e41f4b71Sopenharmony_ci
2431e41f4b71Sopenharmony_ci**Error codes**
2432e41f4b71Sopenharmony_ci
2433e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2434e41f4b71Sopenharmony_ci
2435e41f4b71Sopenharmony_ci| ID| Error Message|
2436e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2437e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2438e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2439e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2440e41f4b71Sopenharmony_ci
2441e41f4b71Sopenharmony_ci**Example**
2442e41f4b71Sopenharmony_ci
2443e41f4b71Sopenharmony_ci```ts
2444e41f4b71Sopenharmony_cicurrentAVSession.off('playPrevious');
2445e41f4b71Sopenharmony_ci```
2446e41f4b71Sopenharmony_ci
2447e41f4b71Sopenharmony_ci### off('fastForward')<sup>10+</sup>
2448e41f4b71Sopenharmony_ci
2449e41f4b71Sopenharmony_cioff(type: 'fastForward', callback?: () => void): void
2450e41f4b71Sopenharmony_ci
2451e41f4b71Sopenharmony_ciUnsubscribes from fastForward command events.
2452e41f4b71Sopenharmony_ci
2453e41f4b71Sopenharmony_ciAfter the callback is canceled, the list of supported commands must be updated.
2454e41f4b71Sopenharmony_ci
2455e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2456e41f4b71Sopenharmony_ci
2457e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2458e41f4b71Sopenharmony_ci
2459e41f4b71Sopenharmony_ci**Parameters**
2460e41f4b71Sopenharmony_ci
2461e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2462e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2463e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'fastForward'** in this case.|
2464e41f4b71Sopenharmony_ci| 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.                           |
2465e41f4b71Sopenharmony_ci
2466e41f4b71Sopenharmony_ci**Error codes**
2467e41f4b71Sopenharmony_ci
2468e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2469e41f4b71Sopenharmony_ci
2470e41f4b71Sopenharmony_ci| ID| Error Message|
2471e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2472e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2473e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2474e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2475e41f4b71Sopenharmony_ci
2476e41f4b71Sopenharmony_ci**Example**
2477e41f4b71Sopenharmony_ci
2478e41f4b71Sopenharmony_ci```ts
2479e41f4b71Sopenharmony_cicurrentAVSession.off('fastForward');
2480e41f4b71Sopenharmony_ci```
2481e41f4b71Sopenharmony_ci
2482e41f4b71Sopenharmony_ci### off('rewind')<sup>10+</sup>
2483e41f4b71Sopenharmony_ci
2484e41f4b71Sopenharmony_cioff(type: 'rewind', callback?: () => void): void
2485e41f4b71Sopenharmony_ci
2486e41f4b71Sopenharmony_ciUnsubscribes from rewind command events.
2487e41f4b71Sopenharmony_ci
2488e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2489e41f4b71Sopenharmony_ci
2490e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2491e41f4b71Sopenharmony_ci
2492e41f4b71Sopenharmony_ci**Parameters**
2493e41f4b71Sopenharmony_ci
2494e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2495e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2496e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'rewind'** in this case.|
2497e41f4b71Sopenharmony_ci| 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.                           |
2498e41f4b71Sopenharmony_ci
2499e41f4b71Sopenharmony_ci**Error codes**
2500e41f4b71Sopenharmony_ci
2501e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2502e41f4b71Sopenharmony_ci
2503e41f4b71Sopenharmony_ci| ID| Error Message|
2504e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2505e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2506e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2507e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2508e41f4b71Sopenharmony_ci
2509e41f4b71Sopenharmony_ci**Example**
2510e41f4b71Sopenharmony_ci
2511e41f4b71Sopenharmony_ci```ts
2512e41f4b71Sopenharmony_cicurrentAVSession.off('rewind');
2513e41f4b71Sopenharmony_ci```
2514e41f4b71Sopenharmony_ci
2515e41f4b71Sopenharmony_ci### off('seek')<sup>10+</sup>
2516e41f4b71Sopenharmony_ci
2517e41f4b71Sopenharmony_cioff(type: 'seek', callback?: (time: number) => void): void
2518e41f4b71Sopenharmony_ci
2519e41f4b71Sopenharmony_ciUnsubscribes from seek command events.
2520e41f4b71Sopenharmony_ci
2521e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2522e41f4b71Sopenharmony_ci
2523e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2524e41f4b71Sopenharmony_ci
2525e41f4b71Sopenharmony_ci**Parameters**
2526e41f4b71Sopenharmony_ci
2527e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                         |
2528e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ----------------------------------------- |
2529e41f4b71Sopenharmony_ci| type     | string                 | Yes  | Event type, which is **'seek'** in this case.      |
2530e41f4b71Sopenharmony_ci| 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.       |
2531e41f4b71Sopenharmony_ci
2532e41f4b71Sopenharmony_ci**Error codes**
2533e41f4b71Sopenharmony_ci
2534e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2535e41f4b71Sopenharmony_ci
2536e41f4b71Sopenharmony_ci| ID| Error Message|
2537e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2538e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2539e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2540e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2541e41f4b71Sopenharmony_ci
2542e41f4b71Sopenharmony_ci**Example**
2543e41f4b71Sopenharmony_ci
2544e41f4b71Sopenharmony_ci```ts
2545e41f4b71Sopenharmony_cicurrentAVSession.off('seek');
2546e41f4b71Sopenharmony_ci```
2547e41f4b71Sopenharmony_ci
2548e41f4b71Sopenharmony_ci### off('setSpeed')<sup>10+</sup>
2549e41f4b71Sopenharmony_ci
2550e41f4b71Sopenharmony_cioff(type: 'setSpeed', callback?: (speed: number) => void): void
2551e41f4b71Sopenharmony_ci
2552e41f4b71Sopenharmony_ciUnsubscribes from setSpeed command events.
2553e41f4b71Sopenharmony_ci
2554e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2555e41f4b71Sopenharmony_ci
2556e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2557e41f4b71Sopenharmony_ci
2558e41f4b71Sopenharmony_ci**Parameters**
2559e41f4b71Sopenharmony_ci
2560e41f4b71Sopenharmony_ci| Name  | Type                   | Mandatory| Description                                          |
2561e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | -------------------------------------------|
2562e41f4b71Sopenharmony_ci| type     | string                  | Yes  | Event type, which is **'setSpeed'** in this case.   |
2563e41f4b71Sopenharmony_ci| 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.                |
2564e41f4b71Sopenharmony_ci
2565e41f4b71Sopenharmony_ci**Error codes**
2566e41f4b71Sopenharmony_ci
2567e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2568e41f4b71Sopenharmony_ci
2569e41f4b71Sopenharmony_ci| ID| Error Message|
2570e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2571e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2572e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2573e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2574e41f4b71Sopenharmony_ci
2575e41f4b71Sopenharmony_ci**Example**
2576e41f4b71Sopenharmony_ci
2577e41f4b71Sopenharmony_ci```ts
2578e41f4b71Sopenharmony_cicurrentAVSession.off('setSpeed');
2579e41f4b71Sopenharmony_ci```
2580e41f4b71Sopenharmony_ci
2581e41f4b71Sopenharmony_ci### off('setLoopMode')<sup>10+</sup>
2582e41f4b71Sopenharmony_ci
2583e41f4b71Sopenharmony_cioff(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void
2584e41f4b71Sopenharmony_ci
2585e41f4b71Sopenharmony_ciUnsubscribes from setSpeed command events.
2586e41f4b71Sopenharmony_ci
2587e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2588e41f4b71Sopenharmony_ci
2589e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2590e41f4b71Sopenharmony_ci
2591e41f4b71Sopenharmony_ci**Parameters**
2592e41f4b71Sopenharmony_ci
2593e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description    |
2594e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ----- |
2595e41f4b71Sopenharmony_ci| type     | string | Yes  | Event type, which is **'setLoopMode'** in this case.|
2596e41f4b71Sopenharmony_ci| 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.|
2597e41f4b71Sopenharmony_ci
2598e41f4b71Sopenharmony_ci**Error codes**
2599e41f4b71Sopenharmony_ci
2600e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2601e41f4b71Sopenharmony_ci
2602e41f4b71Sopenharmony_ci| ID| Error Message|
2603e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2604e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2605e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2606e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2607e41f4b71Sopenharmony_ci
2608e41f4b71Sopenharmony_ci**Example**
2609e41f4b71Sopenharmony_ci
2610e41f4b71Sopenharmony_ci```ts
2611e41f4b71Sopenharmony_cicurrentAVSession.off('setLoopMode');
2612e41f4b71Sopenharmony_ci```
2613e41f4b71Sopenharmony_ci
2614e41f4b71Sopenharmony_ci### off('toggleFavorite')<sup>10+</sup>
2615e41f4b71Sopenharmony_ci
2616e41f4b71Sopenharmony_cioff(type: 'toggleFavorite', callback?: (assetId: string) => void): void
2617e41f4b71Sopenharmony_ci
2618e41f4b71Sopenharmony_ciUnsubscribes from toggleFavorite command events.
2619e41f4b71Sopenharmony_ci
2620e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2621e41f4b71Sopenharmony_ci
2622e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2623e41f4b71Sopenharmony_ci
2624e41f4b71Sopenharmony_ci**Parameters**
2625e41f4b71Sopenharmony_ci
2626e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                                        |
2627e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | -------------------------------------------------------- |
2628e41f4b71Sopenharmony_ci| type     | string                    | Yes  | Event type, which is **'toggleFavorite'** in this case.           |
2629e41f4b71Sopenharmony_ci| 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.                              |
2630e41f4b71Sopenharmony_ci
2631e41f4b71Sopenharmony_ci**Error codes**
2632e41f4b71Sopenharmony_ci
2633e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2634e41f4b71Sopenharmony_ci
2635e41f4b71Sopenharmony_ci| ID| Error Message|
2636e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2637e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2638e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2639e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2640e41f4b71Sopenharmony_ci
2641e41f4b71Sopenharmony_ci**Example**
2642e41f4b71Sopenharmony_ci
2643e41f4b71Sopenharmony_ci```ts
2644e41f4b71Sopenharmony_cicurrentAVSession.off('toggleFavorite');
2645e41f4b71Sopenharmony_ci```
2646e41f4b71Sopenharmony_ci
2647e41f4b71Sopenharmony_ci### off('skipToQueueItem')<sup>10+</sup>
2648e41f4b71Sopenharmony_ci
2649e41f4b71Sopenharmony_cioff(type: 'skipToQueueItem', callback?: (itemId: number) => void): void
2650e41f4b71Sopenharmony_ci
2651e41f4b71Sopenharmony_ciUnsubscribes from the event that indicates an item in the playlist is selected.
2652e41f4b71Sopenharmony_ci
2653e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2654e41f4b71Sopenharmony_ci
2655e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2656e41f4b71Sopenharmony_ci
2657e41f4b71Sopenharmony_ci**Parameters**
2658e41f4b71Sopenharmony_ci
2659e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                                                                                                                                       |
2660e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
2661e41f4b71Sopenharmony_ci| type     | string                   | Yes  | Event type, which is **'skipToQueueItem'** in this case.                                                                                                         |
2662e41f4b71Sopenharmony_ci| 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.|
2663e41f4b71Sopenharmony_ci
2664e41f4b71Sopenharmony_ci**Error codes**
2665e41f4b71Sopenharmony_ci
2666e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2667e41f4b71Sopenharmony_ci
2668e41f4b71Sopenharmony_ci| ID| Error Message|
2669e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2670e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2671e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2672e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2673e41f4b71Sopenharmony_ci
2674e41f4b71Sopenharmony_ci**Example**
2675e41f4b71Sopenharmony_ci
2676e41f4b71Sopenharmony_ci```ts
2677e41f4b71Sopenharmony_cicurrentAVSession.off('skipToQueueItem');
2678e41f4b71Sopenharmony_ci```
2679e41f4b71Sopenharmony_ci
2680e41f4b71Sopenharmony_ci### off('handleKeyEvent')<sup>10+</sup>
2681e41f4b71Sopenharmony_ci
2682e41f4b71Sopenharmony_cioff(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
2683e41f4b71Sopenharmony_ci
2684e41f4b71Sopenharmony_ciUnsubscribes from key events.
2685e41f4b71Sopenharmony_ci
2686e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2687e41f4b71Sopenharmony_ci
2688e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2689e41f4b71Sopenharmony_ci
2690e41f4b71Sopenharmony_ci**Parameters**
2691e41f4b71Sopenharmony_ci
2692e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
2693e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2694e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type, which is **'handleKeyEvent'** in this case.            |
2695e41f4b71Sopenharmony_ci| callback | (event: [KeyEvent](../apis-input-kit/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.                             |
2696e41f4b71Sopenharmony_ci
2697e41f4b71Sopenharmony_ci**Error codes**
2698e41f4b71Sopenharmony_ci
2699e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2700e41f4b71Sopenharmony_ci
2701e41f4b71Sopenharmony_ci| ID| Error Message|
2702e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2703e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2704e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2705e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2706e41f4b71Sopenharmony_ci
2707e41f4b71Sopenharmony_ci**Example**
2708e41f4b71Sopenharmony_ci
2709e41f4b71Sopenharmony_ci```ts
2710e41f4b71Sopenharmony_cicurrentAVSession.off('handleKeyEvent');
2711e41f4b71Sopenharmony_ci```
2712e41f4b71Sopenharmony_ci
2713e41f4b71Sopenharmony_ci### off('outputDeviceChange')<sup>10+</sup>
2714e41f4b71Sopenharmony_ci
2715e41f4b71Sopenharmony_cioff(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2716e41f4b71Sopenharmony_ci
2717e41f4b71Sopenharmony_ciUnsubscribes from playback device change events.
2718e41f4b71Sopenharmony_ci
2719e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2720e41f4b71Sopenharmony_ci
2721e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2722e41f4b71Sopenharmony_ci
2723e41f4b71Sopenharmony_ci**Parameters**
2724e41f4b71Sopenharmony_ci
2725e41f4b71Sopenharmony_ci| Name  | Type                                                   | Mandatory| Description                                                     |
2726e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
2727e41f4b71Sopenharmony_ci| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.    |
2728e41f4b71Sopenharmony_ci| 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.                       |
2729e41f4b71Sopenharmony_ci
2730e41f4b71Sopenharmony_ci**Error codes**
2731e41f4b71Sopenharmony_ci
2732e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2733e41f4b71Sopenharmony_ci
2734e41f4b71Sopenharmony_ci| ID| Error Message|
2735e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2736e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2737e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2738e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2739e41f4b71Sopenharmony_ci
2740e41f4b71Sopenharmony_ci**Example**
2741e41f4b71Sopenharmony_ci
2742e41f4b71Sopenharmony_ci```ts
2743e41f4b71Sopenharmony_cicurrentAVSession.off('outputDeviceChange');
2744e41f4b71Sopenharmony_ci```
2745e41f4b71Sopenharmony_ci
2746e41f4b71Sopenharmony_ci
2747e41f4b71Sopenharmony_ci### off('commonCommand')<sup>10+</sup>
2748e41f4b71Sopenharmony_ci
2749e41f4b71Sopenharmony_cioff(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void
2750e41f4b71Sopenharmony_ci
2751e41f4b71Sopenharmony_ciUnsubscribes from custom control command change events.
2752e41f4b71Sopenharmony_ci
2753e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2754e41f4b71Sopenharmony_ci
2755e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2756e41f4b71Sopenharmony_ci
2757e41f4b71Sopenharmony_ci**Parameters**
2758e41f4b71Sopenharmony_ci
2759e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                    |
2760e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2761e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type, which is **'commonCommand'** in this case.   |
2762e41f4b71Sopenharmony_ci| 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.                     |
2763e41f4b71Sopenharmony_ci
2764e41f4b71Sopenharmony_ci**Error codes**
2765e41f4b71Sopenharmony_ci
2766e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2767e41f4b71Sopenharmony_ci
2768e41f4b71Sopenharmony_ci| ID| Error Message|
2769e41f4b71Sopenharmony_ci| -------- | ---------------- |
2770e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2771e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2772e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2773e41f4b71Sopenharmony_ci
2774e41f4b71Sopenharmony_ci**Example**
2775e41f4b71Sopenharmony_ci
2776e41f4b71Sopenharmony_ci```ts
2777e41f4b71Sopenharmony_cicurrentAVSession.off('commonCommand');
2778e41f4b71Sopenharmony_ci```
2779e41f4b71Sopenharmony_ci
2780e41f4b71Sopenharmony_ci### on('answer')<sup>11+</sup>
2781e41f4b71Sopenharmony_ci
2782e41f4b71Sopenharmony_cion(type: 'answer', callback: Callback\<void>): void;
2783e41f4b71Sopenharmony_ci
2784e41f4b71Sopenharmony_ciSubscribes to call answer events.
2785e41f4b71Sopenharmony_ci
2786e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2787e41f4b71Sopenharmony_ci
2788e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2789e41f4b71Sopenharmony_ci
2790e41f4b71Sopenharmony_ci**Parameters**
2791e41f4b71Sopenharmony_ci
2792e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
2793e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2794e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The event **'answer'** is triggered when a call is answered.|
2795e41f4b71Sopenharmony_ci| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                     |
2796e41f4b71Sopenharmony_ci
2797e41f4b71Sopenharmony_ci**Error codes**
2798e41f4b71Sopenharmony_ci
2799e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2800e41f4b71Sopenharmony_ci
2801e41f4b71Sopenharmony_ci| ID| Error Message|
2802e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
2803e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2804e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2805e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2806e41f4b71Sopenharmony_ci
2807e41f4b71Sopenharmony_ci**Example**
2808e41f4b71Sopenharmony_ci
2809e41f4b71Sopenharmony_ci```ts
2810e41f4b71Sopenharmony_cicurrentAVSession.on('answer', () => {
2811e41f4b71Sopenharmony_ci  console.info('on call answer');
2812e41f4b71Sopenharmony_ci});
2813e41f4b71Sopenharmony_ci```
2814e41f4b71Sopenharmony_ci
2815e41f4b71Sopenharmony_ci### off('answer')<sup>11+</sup>
2816e41f4b71Sopenharmony_ci
2817e41f4b71Sopenharmony_cioff(type: 'answer', callback?: Callback\<void>): void;
2818e41f4b71Sopenharmony_ci
2819e41f4b71Sopenharmony_ciUnsubscribes from call answer events.
2820e41f4b71Sopenharmony_ci
2821e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2822e41f4b71Sopenharmony_ci
2823e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2824e41f4b71Sopenharmony_ci
2825e41f4b71Sopenharmony_ci**Parameters**
2826e41f4b71Sopenharmony_ci
2827e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2828e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2829e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'answer'** in this case.|
2830e41f4b71Sopenharmony_ci| 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.   |
2831e41f4b71Sopenharmony_ci
2832e41f4b71Sopenharmony_ci**Error codes**
2833e41f4b71Sopenharmony_ci
2834e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2835e41f4b71Sopenharmony_ci
2836e41f4b71Sopenharmony_ci| ID| Error Message|
2837e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2838e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2839e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2840e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2841e41f4b71Sopenharmony_ci
2842e41f4b71Sopenharmony_ci**Example**
2843e41f4b71Sopenharmony_ci
2844e41f4b71Sopenharmony_ci```ts
2845e41f4b71Sopenharmony_cicurrentAVSession.off('answer');
2846e41f4b71Sopenharmony_ci```
2847e41f4b71Sopenharmony_ci
2848e41f4b71Sopenharmony_ci### on('hangUp')<sup>11+</sup>
2849e41f4b71Sopenharmony_ci
2850e41f4b71Sopenharmony_cion(type: 'hangUp', callback: Callback\<void>): void;
2851e41f4b71Sopenharmony_ci
2852e41f4b71Sopenharmony_ciSubscribes to call hangup events.
2853e41f4b71Sopenharmony_ci
2854e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2855e41f4b71Sopenharmony_ci
2856e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2857e41f4b71Sopenharmony_ci
2858e41f4b71Sopenharmony_ci**Parameters**
2859e41f4b71Sopenharmony_ci
2860e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
2861e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2862e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The event **'hangUp'** is triggered when a call is hung up.|
2863e41f4b71Sopenharmony_ci| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                                            |
2864e41f4b71Sopenharmony_ci
2865e41f4b71Sopenharmony_ci**Error codes**
2866e41f4b71Sopenharmony_ci
2867e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2868e41f4b71Sopenharmony_ci
2869e41f4b71Sopenharmony_ci| ID| Error Message|
2870e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
2871e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2872e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2873e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2874e41f4b71Sopenharmony_ci
2875e41f4b71Sopenharmony_ci**Example**
2876e41f4b71Sopenharmony_ci
2877e41f4b71Sopenharmony_ci```ts
2878e41f4b71Sopenharmony_cicurrentAVSession.on('hangUp', () => {
2879e41f4b71Sopenharmony_ci  console.info('on call hangUp');
2880e41f4b71Sopenharmony_ci});
2881e41f4b71Sopenharmony_ci```
2882e41f4b71Sopenharmony_ci
2883e41f4b71Sopenharmony_ci### off('hangUp')<sup>11+</sup>
2884e41f4b71Sopenharmony_ci
2885e41f4b71Sopenharmony_cioff(type: 'hangUp', callback?: Callback\<void>): void;
2886e41f4b71Sopenharmony_ci
2887e41f4b71Sopenharmony_ciUnsubscribes from call answer events.
2888e41f4b71Sopenharmony_ci
2889e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2890e41f4b71Sopenharmony_ci
2891e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2892e41f4b71Sopenharmony_ci
2893e41f4b71Sopenharmony_ci**Parameters**
2894e41f4b71Sopenharmony_ci
2895e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2896e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2897e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'hangUp'** in this case.|
2898e41f4b71Sopenharmony_ci| 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.                           |
2899e41f4b71Sopenharmony_ci
2900e41f4b71Sopenharmony_ci**Error codes**
2901e41f4b71Sopenharmony_ci
2902e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2903e41f4b71Sopenharmony_ci
2904e41f4b71Sopenharmony_ci| ID| Error Message|
2905e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2906e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2907e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2908e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2909e41f4b71Sopenharmony_ci
2910e41f4b71Sopenharmony_ci**Example**
2911e41f4b71Sopenharmony_ci
2912e41f4b71Sopenharmony_ci```ts
2913e41f4b71Sopenharmony_cicurrentAVSession.off('hangUp');
2914e41f4b71Sopenharmony_ci```
2915e41f4b71Sopenharmony_ci
2916e41f4b71Sopenharmony_ci### on('toggleCallMute')<sup>11+</sup>
2917e41f4b71Sopenharmony_ci
2918e41f4b71Sopenharmony_cion(type: 'toggleCallMute', callback: Callback\<void>): void;
2919e41f4b71Sopenharmony_ci
2920e41f4b71Sopenharmony_ciSubscribes to call mute events.
2921e41f4b71Sopenharmony_ci
2922e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2923e41f4b71Sopenharmony_ci
2924e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2925e41f4b71Sopenharmony_ci
2926e41f4b71Sopenharmony_ci**Parameters**
2927e41f4b71Sopenharmony_ci
2928e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
2929e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2930e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The event **'toggleCallMute'** is triggered when a call is muted or unmuted.|
2931e41f4b71Sopenharmony_ci| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                                            |
2932e41f4b71Sopenharmony_ci
2933e41f4b71Sopenharmony_ci**Error codes**
2934e41f4b71Sopenharmony_ci
2935e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci| ID| Error Message|
2938e41f4b71Sopenharmony_ci| -------- | ------------------------------ |
2939e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2940e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2941e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2942e41f4b71Sopenharmony_ci
2943e41f4b71Sopenharmony_ci**Example**
2944e41f4b71Sopenharmony_ci
2945e41f4b71Sopenharmony_ci```ts
2946e41f4b71Sopenharmony_cicurrentAVSession.on('toggleCallMute', () => {
2947e41f4b71Sopenharmony_ci  console.info('on call toggleCallMute');
2948e41f4b71Sopenharmony_ci});
2949e41f4b71Sopenharmony_ci```
2950e41f4b71Sopenharmony_ci
2951e41f4b71Sopenharmony_ci### off('toggleCallMute')<sup>11+</sup>
2952e41f4b71Sopenharmony_ci
2953e41f4b71Sopenharmony_cioff(type: 'toggleCallMute', callback?: Callback\<void>): void;
2954e41f4b71Sopenharmony_ci
2955e41f4b71Sopenharmony_ciUnsubscribes from call mute events.
2956e41f4b71Sopenharmony_ci
2957e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2958e41f4b71Sopenharmony_ci
2959e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
2960e41f4b71Sopenharmony_ci
2961e41f4b71Sopenharmony_ci**Parameters**
2962e41f4b71Sopenharmony_ci
2963e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2964e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2965e41f4b71Sopenharmony_ci| type     | string               | Yes  | Event type, which is **'toggleCallMute'** in this case.|
2966e41f4b71Sopenharmony_ci| 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.                           |
2967e41f4b71Sopenharmony_ci
2968e41f4b71Sopenharmony_ci**Error codes**
2969e41f4b71Sopenharmony_ci
2970e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2971e41f4b71Sopenharmony_ci
2972e41f4b71Sopenharmony_ci| ID| Error Message|
2973e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2974e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2975e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
2976e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
2977e41f4b71Sopenharmony_ci
2978e41f4b71Sopenharmony_ci**Example**
2979e41f4b71Sopenharmony_ci
2980e41f4b71Sopenharmony_ci```ts
2981e41f4b71Sopenharmony_cicurrentAVSession.off('toggleCallMute');
2982e41f4b71Sopenharmony_ci```
2983e41f4b71Sopenharmony_ci
2984e41f4b71Sopenharmony_ci### on('castDisplayChange')<sup>12+</sup>
2985e41f4b71Sopenharmony_ci
2986e41f4b71Sopenharmony_cion(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void
2987e41f4b71Sopenharmony_ci
2988e41f4b71Sopenharmony_ciSubscribes to cast display change events in the case of extended screens.
2989e41f4b71Sopenharmony_ci
2990e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2991e41f4b71Sopenharmony_ci
2992e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
2993e41f4b71Sopenharmony_ci
2994e41f4b71Sopenharmony_ci**Parameters**
2995e41f4b71Sopenharmony_ci
2996e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
2997e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2998e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The event **'castDisplayChange'** is triggered when the cast display in the case of extended screens changes.|
2999e41f4b71Sopenharmony_ci| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | Yes  | Callback used to return the information about the cast display.                           |
3000e41f4b71Sopenharmony_ci
3001e41f4b71Sopenharmony_ci**Error codes**
3002e41f4b71Sopenharmony_ci
3003e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3004e41f4b71Sopenharmony_ci
3005e41f4b71Sopenharmony_ci| ID| Error Message|
3006e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
3007e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3008e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
3009e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
3010e41f4b71Sopenharmony_ci
3011e41f4b71Sopenharmony_ci**Example**
3012e41f4b71Sopenharmony_ci
3013e41f4b71Sopenharmony_ci```ts
3014e41f4b71Sopenharmony_cilet castDisplay: avSession.CastDisplayInfo;
3015e41f4b71Sopenharmony_cicurrentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => {
3016e41f4b71Sopenharmony_ci    if (display.state === avSession.CastDisplayState.STATE_ON) {
3017e41f4b71Sopenharmony_ci        castDisplay = display;
3018e41f4b71Sopenharmony_ci        console.info(`Succeeded in castDisplayChange display : ${display.id} ON`);
3019e41f4b71Sopenharmony_ci    } else if (display.state === avSession.CastDisplayState.STATE_OFF){
3020e41f4b71Sopenharmony_ci        console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`);
3021e41f4b71Sopenharmony_ci    }
3022e41f4b71Sopenharmony_ci});
3023e41f4b71Sopenharmony_ci```
3024e41f4b71Sopenharmony_ci### off('castDisplayChange')<sup>12+</sup>
3025e41f4b71Sopenharmony_ci
3026e41f4b71Sopenharmony_ci off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void
3027e41f4b71Sopenharmony_ci
3028e41f4b71Sopenharmony_ciUnsubscribes from cast display change events in the case of extended screens.
3029e41f4b71Sopenharmony_ci
3030e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3031e41f4b71Sopenharmony_ci
3032e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3033e41f4b71Sopenharmony_ci
3034e41f4b71Sopenharmony_ci**Parameters**
3035e41f4b71Sopenharmony_ci
3036e41f4b71Sopenharmony_ci| Name   | Type                 | Mandatory| Description                                                                                                                        |
3037e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3038e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type, which is **'castDisplayChange'** in this case.|
3039e41f4b71Sopenharmony_ci| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
3040e41f4b71Sopenharmony_ci
3041e41f4b71Sopenharmony_ci**Error codes**
3042e41f4b71Sopenharmony_ci
3043e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3044e41f4b71Sopenharmony_ci
3045e41f4b71Sopenharmony_ci| ID| Error Message|
3046e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
3047e41f4b71Sopenharmony_ci| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3048e41f4b71Sopenharmony_ci| 6600101  | Session service exception. |
3049e41f4b71Sopenharmony_ci| 6600102  | The session does not exist. |
3050e41f4b71Sopenharmony_ci
3051e41f4b71Sopenharmony_ci**Example**
3052e41f4b71Sopenharmony_ci
3053e41f4b71Sopenharmony_ci```ts
3054e41f4b71Sopenharmony_cicurrentAVSession.off('castDisplayChange');
3055e41f4b71Sopenharmony_ci```
3056e41f4b71Sopenharmony_ci
3057e41f4b71Sopenharmony_ci### stopCasting<sup>10+</sup>
3058e41f4b71Sopenharmony_ci
3059e41f4b71Sopenharmony_cistopCasting(callback: AsyncCallback\<void>): void
3060e41f4b71Sopenharmony_ci
3061e41f4b71Sopenharmony_ciStops castings. This API uses an asynchronous callback to return the result.
3062e41f4b71Sopenharmony_ci
3063e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3064e41f4b71Sopenharmony_ci
3065e41f4b71Sopenharmony_ci**Parameters**
3066e41f4b71Sopenharmony_ci
3067e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                 |
3068e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- |
3069e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3070e41f4b71Sopenharmony_ci
3071e41f4b71Sopenharmony_ci**Error codes**
3072e41f4b71Sopenharmony_ci
3073e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3074e41f4b71Sopenharmony_ci
3075e41f4b71Sopenharmony_ci| ID| Error Message|
3076e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
3077e41f4b71Sopenharmony_ci| 6600109  | The remote connection is not established. |
3078e41f4b71Sopenharmony_ci
3079e41f4b71Sopenharmony_ci**Example**
3080e41f4b71Sopenharmony_ci
3081e41f4b71Sopenharmony_ci```ts
3082e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3083e41f4b71Sopenharmony_ci
3084e41f4b71Sopenharmony_cicurrentAVSession.stopCasting((err: BusinessError) => {
3085e41f4b71Sopenharmony_ci  if (err) {
3086e41f4b71Sopenharmony_ci    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3087e41f4b71Sopenharmony_ci  } else {
3088e41f4b71Sopenharmony_ci    console.info('stopCasting successfully');
3089e41f4b71Sopenharmony_ci  }
3090e41f4b71Sopenharmony_ci});
3091e41f4b71Sopenharmony_ci```
3092e41f4b71Sopenharmony_ci
3093e41f4b71Sopenharmony_ci### stopCasting<sup>10+</sup>
3094e41f4b71Sopenharmony_ci
3095e41f4b71Sopenharmony_cistopCasting(): Promise\<void>
3096e41f4b71Sopenharmony_ci
3097e41f4b71Sopenharmony_ciStops castings. This API uses a promise to return the result.
3098e41f4b71Sopenharmony_ci
3099e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3100e41f4b71Sopenharmony_ci
3101e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3102e41f4b71Sopenharmony_ci
3103e41f4b71Sopenharmony_ci**Return value**
3104e41f4b71Sopenharmony_ci
3105e41f4b71Sopenharmony_ci| Type          | Description                         |
3106e41f4b71Sopenharmony_ci| -------------- | ----------------------------- |
3107e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.|
3108e41f4b71Sopenharmony_ci
3109e41f4b71Sopenharmony_ci**Error codes**
3110e41f4b71Sopenharmony_ci
3111e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3112e41f4b71Sopenharmony_ci
3113e41f4b71Sopenharmony_ci| ID| Error Message|
3114e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
3115e41f4b71Sopenharmony_ci| 6600109  | The remote connection is not established. |
3116e41f4b71Sopenharmony_ci
3117e41f4b71Sopenharmony_ci**Example**
3118e41f4b71Sopenharmony_ci
3119e41f4b71Sopenharmony_ci```ts
3120e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3121e41f4b71Sopenharmony_ci
3122e41f4b71Sopenharmony_cicurrentAVSession.stopCasting().then(() => {
3123e41f4b71Sopenharmony_ci  console.info('stopCasting successfully');
3124e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3125e41f4b71Sopenharmony_ci  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3126e41f4b71Sopenharmony_ci});
3127e41f4b71Sopenharmony_ci```
3128e41f4b71Sopenharmony_ci
3129e41f4b71Sopenharmony_ci### getOutputDeviceSync<sup>10+</sup>
3130e41f4b71Sopenharmony_ci
3131e41f4b71Sopenharmony_cigetOutputDeviceSync(): OutputDeviceInfo
3132e41f4b71Sopenharmony_ci
3133e41f4b71Sopenharmony_ciObtains the output device information. This API returns the result synchronously.
3134e41f4b71Sopenharmony_ci
3135e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3136e41f4b71Sopenharmony_ci
3137e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
3138e41f4b71Sopenharmony_ci
3139e41f4b71Sopenharmony_ci**Return value**
3140e41f4b71Sopenharmony_ci
3141e41f4b71Sopenharmony_ci| Type                                           | Description                             |
3142e41f4b71Sopenharmony_ci| ----------------------------------------------- | --------------------------------- |
3143e41f4b71Sopenharmony_ci| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.|
3144e41f4b71Sopenharmony_ci
3145e41f4b71Sopenharmony_ci**Error codes**
3146e41f4b71Sopenharmony_ci
3147e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3148e41f4b71Sopenharmony_ci
3149e41f4b71Sopenharmony_ci| ID  | Error Message|
3150e41f4b71Sopenharmony_ci|---------| --------------------------------------- |
3151e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3152e41f4b71Sopenharmony_ci| 6600102 | The session does not exist. |
3153e41f4b71Sopenharmony_ci
3154e41f4b71Sopenharmony_ci**Example**
3155e41f4b71Sopenharmony_ci
3156e41f4b71Sopenharmony_ci```ts
3157e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3158e41f4b71Sopenharmony_ci
3159e41f4b71Sopenharmony_citry {
3160e41f4b71Sopenharmony_ci  let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync();
3161e41f4b71Sopenharmony_ci} catch (err) {
3162e41f4b71Sopenharmony_ci  let error = err as BusinessError;
3163e41f4b71Sopenharmony_ci  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
3164e41f4b71Sopenharmony_ci}
3165e41f4b71Sopenharmony_ci```
3166e41f4b71Sopenharmony_ci### getAllCastDisplays<sup>12+</sup>
3167e41f4b71Sopenharmony_ci
3168e41f4b71Sopenharmony_cigetAllCastDisplays(): Promise<Array\<CastDisplayInfo>>
3169e41f4b71Sopenharmony_ci
3170e41f4b71Sopenharmony_ciObtains all displays that support extended screen projection in the current system. This API uses a promise to return the result.
3171e41f4b71Sopenharmony_ci
3172e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3173e41f4b71Sopenharmony_ci
3174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3175e41f4b71Sopenharmony_ci
3176e41f4b71Sopenharmony_ci**Return value**
3177e41f4b71Sopenharmony_ci
3178e41f4b71Sopenharmony_ci| Type                                           | Description                             |
3179e41f4b71Sopenharmony_ci| ----------------------------------------------- | --------------------------------- |
3180e41f4b71Sopenharmony_ci| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise used to return the information about all the cast displays.|
3181e41f4b71Sopenharmony_ci
3182e41f4b71Sopenharmony_ci**Error codes**
3183e41f4b71Sopenharmony_ci
3184e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3185e41f4b71Sopenharmony_ci
3186e41f4b71Sopenharmony_ci| ID  | Error Message|
3187e41f4b71Sopenharmony_ci|---------| --------------------------------------- |
3188e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3189e41f4b71Sopenharmony_ci| 6600102 | The session does not exist. |
3190e41f4b71Sopenharmony_ci
3191e41f4b71Sopenharmony_ci**Example**
3192e41f4b71Sopenharmony_ci
3193e41f4b71Sopenharmony_ci```ts
3194e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3195e41f4b71Sopenharmony_ci
3196e41f4b71Sopenharmony_cilet castDisplay: avSession.CastDisplayInfo;
3197e41f4b71Sopenharmony_cicurrentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => {
3198e41f4b71Sopenharmony_ci    if (data.length >= 1) {
3199e41f4b71Sopenharmony_ci       castDisplay = data[0];
3200e41f4b71Sopenharmony_ci     }
3201e41f4b71Sopenharmony_ci   }).catch((err: BusinessError) => {
3202e41f4b71Sopenharmony_ci     console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`);
3203e41f4b71Sopenharmony_ci   });
3204e41f4b71Sopenharmony_ci```
3205e41f4b71Sopenharmony_ci
3206e41f4b71Sopenharmony_ci## AVCastControlCommandType<sup>10+</sup>
3207e41f4b71Sopenharmony_ci
3208e41f4b71Sopenharmony_citype AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
3209e41f4b71Sopenharmony_ci  'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute'
3210e41f4b71Sopenharmony_ci
3211e41f4b71Sopenharmony_ciEnumerates the commands that can be sent by a cast controller.
3212e41f4b71Sopenharmony_ci
3213e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3214e41f4b71Sopenharmony_ci
3215e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3216e41f4b71Sopenharmony_ci
3217e41f4b71Sopenharmony_ci| Type             | Description                    |
3218e41f4b71Sopenharmony_ci| ---------------- | ------------------------------ |
3219e41f4b71Sopenharmony_ci| 'play'           | Play the media.                |
3220e41f4b71Sopenharmony_ci| 'pause'          | Pause the playback.            |
3221e41f4b71Sopenharmony_ci| 'stop'           | Stop the playback.             |
3222e41f4b71Sopenharmony_ci| 'playNext'       | Play the next media asset.     |
3223e41f4b71Sopenharmony_ci| 'playPrevious'   | Play the previous media asset. |
3224e41f4b71Sopenharmony_ci| 'fastForward'    | Fast-forward.                  |
3225e41f4b71Sopenharmony_ci| 'rewind'         | Rewind.                        |
3226e41f4b71Sopenharmony_ci| 'seek'           | Seek to a playback position.   |
3227e41f4b71Sopenharmony_ci| 'setVolume'      | Set the volume.                |
3228e41f4b71Sopenharmony_ci| 'setSpeed'       | Set the playback speed.        |
3229e41f4b71Sopenharmony_ci| 'setLoopMode'    | Set the loop mode.             |
3230e41f4b71Sopenharmony_ci| 'toggleFavorite' | Favorite the media asset.      |
3231e41f4b71Sopenharmony_ci| 'toggleMute'     | Set the mute status.           |
3232e41f4b71Sopenharmony_ci
3233e41f4b71Sopenharmony_ci## AVCastControlCommand<sup>10+</sup>
3234e41f4b71Sopenharmony_ci
3235e41f4b71Sopenharmony_ciDefines the command that can be sent by a cast controller.
3236e41f4b71Sopenharmony_ci
3237e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3238e41f4b71Sopenharmony_ci
3239e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3240e41f4b71Sopenharmony_ci
3241e41f4b71Sopenharmony_ci| Name      | Type                                                         | Mandatory | Description                        |
3242e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------------ | --------- | ---------------------------------- |
3243e41f4b71Sopenharmony_ci| command   | [AVCastControlCommandType](#avcastcontrolcommandtype10)      | Yes       | Command.                           |
3244e41f4b71Sopenharmony_ci| parameter | [media.PlaybackSpeed](../apis-media-kit/js-apis-media.md#playbackspeed8) &#124; number &#124; string &#124; [LoopMode](#loopmode10) | No        | Parameters carried in the command. |
3245e41f4b71Sopenharmony_ci
3246e41f4b71Sopenharmony_ci## AVCastController<sup>10+</sup>
3247e41f4b71Sopenharmony_ci
3248e41f4b71Sopenharmony_ciAfter 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.
3249e41f4b71Sopenharmony_ci
3250e41f4b71Sopenharmony_ci### getAVPlaybackState<sup>10+</sup>
3251e41f4b71Sopenharmony_ci
3252e41f4b71Sopenharmony_cigetAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
3253e41f4b71Sopenharmony_ci
3254e41f4b71Sopenharmony_ciObtains the remote playback state. This API uses an asynchronous callback to return the result.
3255e41f4b71Sopenharmony_ci
3256e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3257e41f4b71Sopenharmony_ci
3258e41f4b71Sopenharmony_ci**Parameters**
3259e41f4b71Sopenharmony_ci
3260e41f4b71Sopenharmony_ci| Name     | Type                                                  | Mandatory | Description                                        |
3261e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | --------- | -------------------------------------------------- |
3262e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes       | Callback used to return the remote playback state. |
3263e41f4b71Sopenharmony_ci
3264e41f4b71Sopenharmony_ci**Error codes**
3265e41f4b71Sopenharmony_ci
3266e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3267e41f4b71Sopenharmony_ci
3268e41f4b71Sopenharmony_ci| ID      | Error Message             |
3269e41f4b71Sopenharmony_ci| ------- | ------------------------- |
3270e41f4b71Sopenharmony_ci| 6600101 | Session service exception |
3271e41f4b71Sopenharmony_ci
3272e41f4b71Sopenharmony_ci**Example**
3273e41f4b71Sopenharmony_ci
3274e41f4b71Sopenharmony_ci```ts
3275e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3276e41f4b71Sopenharmony_ci
3277e41f4b71Sopenharmony_ciaVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
3278e41f4b71Sopenharmony_ci  if (err) {
3279e41f4b71Sopenharmony_ci    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3280e41f4b71Sopenharmony_ci  } else {
3281e41f4b71Sopenharmony_ci    console.info('getAVPlaybackState : SUCCESS');
3282e41f4b71Sopenharmony_ci  }
3283e41f4b71Sopenharmony_ci});
3284e41f4b71Sopenharmony_ci```
3285e41f4b71Sopenharmony_ci
3286e41f4b71Sopenharmony_ci### getAVPlaybackState<sup>10+</sup>
3287e41f4b71Sopenharmony_ci
3288e41f4b71Sopenharmony_cigetAVPlaybackState(): Promise\<AVPlaybackState>
3289e41f4b71Sopenharmony_ci
3290e41f4b71Sopenharmony_ciObtains the remote playback state. This API uses a promise to return the result.
3291e41f4b71Sopenharmony_ci
3292e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3293e41f4b71Sopenharmony_ci
3294e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3295e41f4b71Sopenharmony_ci
3296e41f4b71Sopenharmony_ci**Return value**
3297e41f4b71Sopenharmony_ci
3298e41f4b71Sopenharmony_ci| Type                                            | Description                                       |
3299e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------- |
3300e41f4b71Sopenharmony_ci| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state. |
3301e41f4b71Sopenharmony_ci
3302e41f4b71Sopenharmony_ci**Error codes**
3303e41f4b71Sopenharmony_ci
3304e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3305e41f4b71Sopenharmony_ci
3306e41f4b71Sopenharmony_ci| ID      | Error Message             |
3307e41f4b71Sopenharmony_ci| ------- | ------------------------- |
3308e41f4b71Sopenharmony_ci| 6600101 | Session service exception |
3309e41f4b71Sopenharmony_ci
3310e41f4b71Sopenharmony_ci**Example**
3311e41f4b71Sopenharmony_ci
3312e41f4b71Sopenharmony_ci```ts
3313e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3314e41f4b71Sopenharmony_ci
3315e41f4b71Sopenharmony_ciaVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
3316e41f4b71Sopenharmony_ci  console.info('getAVPlaybackState : SUCCESS');
3317e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3318e41f4b71Sopenharmony_ci  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3319e41f4b71Sopenharmony_ci});
3320e41f4b71Sopenharmony_ci```
3321e41f4b71Sopenharmony_ci
3322e41f4b71Sopenharmony_ci### sendControlCommand<sup>10+</sup>
3323e41f4b71Sopenharmony_ci
3324e41f4b71Sopenharmony_cisendControlCommand(command: AVCastControlCommand): Promise\<void>
3325e41f4b71Sopenharmony_ci
3326e41f4b71Sopenharmony_ciSends a control command to the session through the controller. This API uses a promise to return the result.
3327e41f4b71Sopenharmony_ci
3328e41f4b71Sopenharmony_ci
3329e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3330e41f4b71Sopenharmony_ci
3331e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3332e41f4b71Sopenharmony_ci
3333e41f4b71Sopenharmony_ci**Parameters**
3334e41f4b71Sopenharmony_ci
3335e41f4b71Sopenharmony_ci| Name    | Type                                            | Mandatory | Description      |
3336e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------- | --------- | ---------------- |
3337e41f4b71Sopenharmony_ci| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes       | Command to send. |
3338e41f4b71Sopenharmony_ci
3339e41f4b71Sopenharmony_ci**Return value**
3340e41f4b71Sopenharmony_ci
3341e41f4b71Sopenharmony_ci| Type           | Description                                                  |
3342e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
3343e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. |
3344e41f4b71Sopenharmony_ci
3345e41f4b71Sopenharmony_ci**Error codes**
3346e41f4b71Sopenharmony_ci
3347e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3348e41f4b71Sopenharmony_ci
3349e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3350e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3351e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3352e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3353e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
3354e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established.                    |
3355e41f4b71Sopenharmony_ci
3356e41f4b71Sopenharmony_ci**Example**
3357e41f4b71Sopenharmony_ci
3358e41f4b71Sopenharmony_ci```ts
3359e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3360e41f4b71Sopenharmony_ci
3361e41f4b71Sopenharmony_cilet avCommand: avSession.AVCastControlCommand = {command:'play'};
3362e41f4b71Sopenharmony_ciaVCastController.sendControlCommand(avCommand).then(() => {
3363e41f4b71Sopenharmony_ci  console.info('SendControlCommand successfully');
3364e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3365e41f4b71Sopenharmony_ci  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3366e41f4b71Sopenharmony_ci});
3367e41f4b71Sopenharmony_ci```
3368e41f4b71Sopenharmony_ci
3369e41f4b71Sopenharmony_ci### sendControlCommand<sup>10+</sup>
3370e41f4b71Sopenharmony_ci
3371e41f4b71Sopenharmony_cisendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void
3372e41f4b71Sopenharmony_ci
3373e41f4b71Sopenharmony_ciSends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
3374e41f4b71Sopenharmony_ci
3375e41f4b71Sopenharmony_ci
3376e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3377e41f4b71Sopenharmony_ci
3378e41f4b71Sopenharmony_ci**Parameters**
3379e41f4b71Sopenharmony_ci
3380e41f4b71Sopenharmony_ci| Name     | Type                                            | Mandatory | Description                                                  |
3381e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | --------- | ------------------------------------------------------------ |
3382e41f4b71Sopenharmony_ci| command  | [AVCastControlCommand](#avcastcontrolcommand10) | Yes       | Command to send.                                             |
3383e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                            | Yes       | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. |
3384e41f4b71Sopenharmony_ci
3385e41f4b71Sopenharmony_ci**Error codes**
3386e41f4b71Sopenharmony_ci
3387e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3388e41f4b71Sopenharmony_ci
3389e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3390e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3391e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3392e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3393e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
3394e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established.                    |
3395e41f4b71Sopenharmony_ci
3396e41f4b71Sopenharmony_ci**Example**
3397e41f4b71Sopenharmony_ci
3398e41f4b71Sopenharmony_ci```ts
3399e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3400e41f4b71Sopenharmony_ci
3401e41f4b71Sopenharmony_cilet avCommand: avSession.AVCastControlCommand = {command:'play'};
3402e41f4b71Sopenharmony_ciaVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
3403e41f4b71Sopenharmony_ci  if (err) {
3404e41f4b71Sopenharmony_ci    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3405e41f4b71Sopenharmony_ci  } else {
3406e41f4b71Sopenharmony_ci    console.info('SendControlCommand successfully');
3407e41f4b71Sopenharmony_ci  }
3408e41f4b71Sopenharmony_ci});
3409e41f4b71Sopenharmony_ci```
3410e41f4b71Sopenharmony_ci
3411e41f4b71Sopenharmony_ci### prepare<sup>10+</sup>
3412e41f4b71Sopenharmony_ci
3413e41f4b71Sopenharmony_ciprepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
3414e41f4b71Sopenharmony_ci
3415e41f4b71Sopenharmony_ciPrepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses an asynchronous callback to return the result.
3416e41f4b71Sopenharmony_ci
3417e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3418e41f4b71Sopenharmony_ci
3419e41f4b71Sopenharmony_ci**Parameters**
3420e41f4b71Sopenharmony_ci
3421e41f4b71Sopenharmony_ci| Name     | Type                          | Mandatory | Description                                                  |
3422e41f4b71Sopenharmony_ci| -------- | ----------------------------- | --------- | ------------------------------------------------------------ |
3423e41f4b71Sopenharmony_ci| item     | [AVQueueItem](#avqueueitem10) | Yes       | Attributes of an item in the playlist.                       |
3424e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>          | Yes       | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. |
3425e41f4b71Sopenharmony_ci
3426e41f4b71Sopenharmony_ci**Error codes**
3427e41f4b71Sopenharmony_ci
3428e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3429e41f4b71Sopenharmony_ci
3430e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3431e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3432e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3433e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3434e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established.                    |
3435e41f4b71Sopenharmony_ci
3436e41f4b71Sopenharmony_ci**Example**
3437e41f4b71Sopenharmony_ci
3438e41f4b71Sopenharmony_ci```ts
3439e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3440e41f4b71Sopenharmony_ci
3441e41f4b71Sopenharmony_ci// Set playback parameters.
3442e41f4b71Sopenharmony_cilet playItem: avSession.AVQueueItem = {
3443e41f4b71Sopenharmony_ci  itemId: 0,
3444e41f4b71Sopenharmony_ci  description: {
3445e41f4b71Sopenharmony_ci    assetId: '12345',
3446e41f4b71Sopenharmony_ci    mediaType: 'AUDIO',
3447e41f4b71Sopenharmony_ci    mediaUri: 'http://resource1_address',
3448e41f4b71Sopenharmony_ci    mediaSize: 12345,
3449e41f4b71Sopenharmony_ci    startPosition: 0,
3450e41f4b71Sopenharmony_ci    duration: 0,
3451e41f4b71Sopenharmony_ci    artist: 'mysong',
3452e41f4b71Sopenharmony_ci    albumTitle: 'song1_title',
3453e41f4b71Sopenharmony_ci    albumCoverUri: "http://resource1_album_address",
3454e41f4b71Sopenharmony_ci    lyricUri: "http://resource1_lyric_address",
3455e41f4b71Sopenharmony_ci    appName: 'MyMusic'
3456e41f4b71Sopenharmony_ci  }
3457e41f4b71Sopenharmony_ci};
3458e41f4b71Sopenharmony_ci// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
3459e41f4b71Sopenharmony_ciaVCastController.prepare(playItem, (err: BusinessError) => {
3460e41f4b71Sopenharmony_ci  if (err) {
3461e41f4b71Sopenharmony_ci    console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3462e41f4b71Sopenharmony_ci  } else {
3463e41f4b71Sopenharmony_ci    console.info('prepare successfully');
3464e41f4b71Sopenharmony_ci  }
3465e41f4b71Sopenharmony_ci});
3466e41f4b71Sopenharmony_ci```
3467e41f4b71Sopenharmony_ci
3468e41f4b71Sopenharmony_ci
3469e41f4b71Sopenharmony_ci### prepare<sup>10+</sup>
3470e41f4b71Sopenharmony_ci
3471e41f4b71Sopenharmony_ciprepare(item: AVQueueItem): Promise\<void>
3472e41f4b71Sopenharmony_ci
3473e41f4b71Sopenharmony_ciPrepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses a promise to return the result.
3474e41f4b71Sopenharmony_ci
3475e41f4b71Sopenharmony_ci
3476e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3477e41f4b71Sopenharmony_ci
3478e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3479e41f4b71Sopenharmony_ci
3480e41f4b71Sopenharmony_ci**Parameters**
3481e41f4b71Sopenharmony_ci
3482e41f4b71Sopenharmony_ci| Name | Type                          | Mandatory | Description                            |
3483e41f4b71Sopenharmony_ci| ---- | ----------------------------- | --------- | -------------------------------------- |
3484e41f4b71Sopenharmony_ci| item | [AVQueueItem](#avqueueitem10) | Yes       | Attributes of an item in the playlist. |
3485e41f4b71Sopenharmony_ci
3486e41f4b71Sopenharmony_ci**Return value**
3487e41f4b71Sopenharmony_ci
3488e41f4b71Sopenharmony_ci| Type           | Description                                                  |
3489e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
3490e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. |
3491e41f4b71Sopenharmony_ci
3492e41f4b71Sopenharmony_ci**Error codes**
3493e41f4b71Sopenharmony_ci
3494e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3495e41f4b71Sopenharmony_ci
3496e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3497e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3498e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3499e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3500e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established.                    |
3501e41f4b71Sopenharmony_ci
3502e41f4b71Sopenharmony_ci
3503e41f4b71Sopenharmony_ci**Example**
3504e41f4b71Sopenharmony_ci
3505e41f4b71Sopenharmony_ci```ts
3506e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3507e41f4b71Sopenharmony_ci
3508e41f4b71Sopenharmony_ci// Set playback parameters.
3509e41f4b71Sopenharmony_cilet playItem: avSession.AVQueueItem = {
3510e41f4b71Sopenharmony_ci  itemId: 0,
3511e41f4b71Sopenharmony_ci  description: {
3512e41f4b71Sopenharmony_ci    assetId: '12345',
3513e41f4b71Sopenharmony_ci    mediaType: 'AUDIO',
3514e41f4b71Sopenharmony_ci    mediaUri: 'http://resource1_address',
3515e41f4b71Sopenharmony_ci    mediaSize: 12345,
3516e41f4b71Sopenharmony_ci    startPosition: 0,
3517e41f4b71Sopenharmony_ci    duration: 0,
3518e41f4b71Sopenharmony_ci    artist: 'mysong',
3519e41f4b71Sopenharmony_ci    albumTitle: 'song1_title',
3520e41f4b71Sopenharmony_ci    albumCoverUri: "http://resource1_album_address",
3521e41f4b71Sopenharmony_ci    lyricUri: "http://resource1_lyric_address",
3522e41f4b71Sopenharmony_ci    appName: 'MyMusic'
3523e41f4b71Sopenharmony_ci  }
3524e41f4b71Sopenharmony_ci};
3525e41f4b71Sopenharmony_ci// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
3526e41f4b71Sopenharmony_ciaVCastController.prepare(playItem).then(() => {
3527e41f4b71Sopenharmony_ci  console.info('prepare successfully');
3528e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3529e41f4b71Sopenharmony_ci  console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3530e41f4b71Sopenharmony_ci});
3531e41f4b71Sopenharmony_ci```
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_ci### start<sup>10+</sup>
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_cistart(item: AVQueueItem, callback: AsyncCallback\<void>): void
3536e41f4b71Sopenharmony_ci
3537e41f4b71Sopenharmony_ciPrepares for the playback of a media asset. This API uses an asynchronous callback to return the result.
3538e41f4b71Sopenharmony_ci
3539e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3540e41f4b71Sopenharmony_ci
3541e41f4b71Sopenharmony_ci**Parameters**
3542e41f4b71Sopenharmony_ci
3543e41f4b71Sopenharmony_ci| Name     | Type                          | Mandatory | Description                                                  |
3544e41f4b71Sopenharmony_ci| -------- | ----------------------------- | --------- | ------------------------------------------------------------ |
3545e41f4b71Sopenharmony_ci| item     | [AVQueueItem](#avqueueitem10) | Yes       | Attributes of an item in the playlist.                       |
3546e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>          | Yes       | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. |
3547e41f4b71Sopenharmony_ci
3548e41f4b71Sopenharmony_ci**Error codes**
3549e41f4b71Sopenharmony_ci
3550e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3551e41f4b71Sopenharmony_ci
3552e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3553e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3554e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3555e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3556e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established.                    |
3557e41f4b71Sopenharmony_ci
3558e41f4b71Sopenharmony_ci**Example**
3559e41f4b71Sopenharmony_ci
3560e41f4b71Sopenharmony_ci```ts
3561e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3562e41f4b71Sopenharmony_ci
3563e41f4b71Sopenharmony_ci// Set playback parameters.
3564e41f4b71Sopenharmony_cilet playItem: avSession.AVQueueItem = {
3565e41f4b71Sopenharmony_ci  itemId: 0,
3566e41f4b71Sopenharmony_ci  description: {
3567e41f4b71Sopenharmony_ci    assetId: '12345',
3568e41f4b71Sopenharmony_ci    mediaType: 'AUDIO',
3569e41f4b71Sopenharmony_ci    mediaUri: 'http://resource1_address',
3570e41f4b71Sopenharmony_ci    mediaSize: 12345,
3571e41f4b71Sopenharmony_ci    startPosition: 0,
3572e41f4b71Sopenharmony_ci    duration: 0,
3573e41f4b71Sopenharmony_ci    artist: 'mysong',
3574e41f4b71Sopenharmony_ci    albumTitle: 'song1_title',
3575e41f4b71Sopenharmony_ci    albumCoverUri: "http://resource1_album_address",
3576e41f4b71Sopenharmony_ci    lyricUri: "http://resource1_lyric_address",
3577e41f4b71Sopenharmony_ci    appName: 'MyMusic'
3578e41f4b71Sopenharmony_ci  }
3579e41f4b71Sopenharmony_ci};
3580e41f4b71Sopenharmony_ci
3581e41f4b71Sopenharmony_ci// Start playback.
3582e41f4b71Sopenharmony_ciaVCastController.start(playItem, (err: BusinessError) => {
3583e41f4b71Sopenharmony_ci  if (err) {
3584e41f4b71Sopenharmony_ci    console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3585e41f4b71Sopenharmony_ci  } else {
3586e41f4b71Sopenharmony_ci    console.info('start successfully');
3587e41f4b71Sopenharmony_ci  }
3588e41f4b71Sopenharmony_ci});
3589e41f4b71Sopenharmony_ci```
3590e41f4b71Sopenharmony_ci
3591e41f4b71Sopenharmony_ci### start<sup>10+</sup>
3592e41f4b71Sopenharmony_ci
3593e41f4b71Sopenharmony_cistart(item: AVQueueItem): Promise\<void>
3594e41f4b71Sopenharmony_ci
3595e41f4b71Sopenharmony_ciPrepares for the playback of a media asset. This API uses a promise to return the result.
3596e41f4b71Sopenharmony_ci
3597e41f4b71Sopenharmony_ci
3598e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3599e41f4b71Sopenharmony_ci
3600e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3601e41f4b71Sopenharmony_ci
3602e41f4b71Sopenharmony_ci**Parameters**
3603e41f4b71Sopenharmony_ci
3604e41f4b71Sopenharmony_ci| Name | Type                          | Mandatory | Description                            |
3605e41f4b71Sopenharmony_ci| ---- | ----------------------------- | --------- | -------------------------------------- |
3606e41f4b71Sopenharmony_ci| item | [AVQueueItem](#avqueueitem10) | Yes       | Attributes of an item in the playlist. |
3607e41f4b71Sopenharmony_ci
3608e41f4b71Sopenharmony_ci**Return value**
3609e41f4b71Sopenharmony_ci
3610e41f4b71Sopenharmony_ci| Type           | Description                                                  |
3611e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
3612e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. |
3613e41f4b71Sopenharmony_ci
3614e41f4b71Sopenharmony_ci**Error codes**
3615e41f4b71Sopenharmony_ci
3616e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3617e41f4b71Sopenharmony_ci
3618e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3619e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3620e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3621e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3622e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established.                    |
3623e41f4b71Sopenharmony_ci
3624e41f4b71Sopenharmony_ci
3625e41f4b71Sopenharmony_ci**Example**
3626e41f4b71Sopenharmony_ci
3627e41f4b71Sopenharmony_ci```ts
3628e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3629e41f4b71Sopenharmony_ci
3630e41f4b71Sopenharmony_ci// Set playback parameters.
3631e41f4b71Sopenharmony_cilet playItem: avSession.AVQueueItem = {
3632e41f4b71Sopenharmony_ci  itemId: 0,
3633e41f4b71Sopenharmony_ci  description: {
3634e41f4b71Sopenharmony_ci    assetId: '12345',
3635e41f4b71Sopenharmony_ci    mediaType: 'AUDIO',
3636e41f4b71Sopenharmony_ci    mediaUri: 'http://resource1_address',
3637e41f4b71Sopenharmony_ci    mediaSize: 12345,
3638e41f4b71Sopenharmony_ci    startPosition: 0,
3639e41f4b71Sopenharmony_ci    duration: 0,
3640e41f4b71Sopenharmony_ci    artist: 'mysong',
3641e41f4b71Sopenharmony_ci    albumTitle: 'song1_title',
3642e41f4b71Sopenharmony_ci    albumCoverUri: "http://resource1_album_address",
3643e41f4b71Sopenharmony_ci    lyricUri: "http://resource1_lyric_address",
3644e41f4b71Sopenharmony_ci    appName: 'MyMusic'
3645e41f4b71Sopenharmony_ci  }
3646e41f4b71Sopenharmony_ci};
3647e41f4b71Sopenharmony_ci// Start playback.
3648e41f4b71Sopenharmony_ciaVCastController.start(playItem).then(() => {
3649e41f4b71Sopenharmony_ci  console.info('start successfully');
3650e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3651e41f4b71Sopenharmony_ci  console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3652e41f4b71Sopenharmony_ci});
3653e41f4b71Sopenharmony_ci```
3654e41f4b71Sopenharmony_ci
3655e41f4b71Sopenharmony_ci### getCurrentItem<sup>10+</sup>
3656e41f4b71Sopenharmony_ci
3657e41f4b71Sopenharmony_cigetCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
3658e41f4b71Sopenharmony_ci
3659e41f4b71Sopenharmony_ciObtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result.
3660e41f4b71Sopenharmony_ci
3661e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3662e41f4b71Sopenharmony_ci
3663e41f4b71Sopenharmony_ci**Parameters**
3664e41f4b71Sopenharmony_ci
3665e41f4b71Sopenharmony_ci| Name     | Type                                          | Mandatory | Description                                                  |
3666e41f4b71Sopenharmony_ci| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
3667e41f4b71Sopenharmony_ci| 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. |
3668e41f4b71Sopenharmony_ci
3669e41f4b71Sopenharmony_ci**Error codes**
3670e41f4b71Sopenharmony_ci
3671e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3672e41f4b71Sopenharmony_ci
3673e41f4b71Sopenharmony_ci| ID      | Error Message              |
3674e41f4b71Sopenharmony_ci| ------- | -------------------------- |
3675e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3676e41f4b71Sopenharmony_ci
3677e41f4b71Sopenharmony_ci**Example**
3678e41f4b71Sopenharmony_ci
3679e41f4b71Sopenharmony_ci```ts
3680e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3681e41f4b71Sopenharmony_ci
3682e41f4b71Sopenharmony_ciaVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
3683e41f4b71Sopenharmony_ci  if (err) {
3684e41f4b71Sopenharmony_ci    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3685e41f4b71Sopenharmony_ci  } else {
3686e41f4b71Sopenharmony_ci    console.info('getCurrentItem successfully');
3687e41f4b71Sopenharmony_ci  }
3688e41f4b71Sopenharmony_ci});
3689e41f4b71Sopenharmony_ci```
3690e41f4b71Sopenharmony_ci
3691e41f4b71Sopenharmony_ci### getCurrentItem<sup>10+</sup>
3692e41f4b71Sopenharmony_ci
3693e41f4b71Sopenharmony_cigetCurrentItem(): Promise\<AVQueueItem>
3694e41f4b71Sopenharmony_ci
3695e41f4b71Sopenharmony_ciObtains the information about the media asset that is being played. This API uses a promise to return the result.
3696e41f4b71Sopenharmony_ci
3697e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3698e41f4b71Sopenharmony_ci
3699e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3700e41f4b71Sopenharmony_ci
3701e41f4b71Sopenharmony_ci**Return value**
3702e41f4b71Sopenharmony_ci
3703e41f4b71Sopenharmony_ci| Type                                    | Description                                                  |
3704e41f4b71Sopenharmony_ci| --------------------------------------- | ------------------------------------------------------------ |
3705e41f4b71Sopenharmony_ci| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned. |
3706e41f4b71Sopenharmony_ci
3707e41f4b71Sopenharmony_ci**Error codes**
3708e41f4b71Sopenharmony_ci
3709e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3710e41f4b71Sopenharmony_ci
3711e41f4b71Sopenharmony_ci| ID      | Error Message              |
3712e41f4b71Sopenharmony_ci| ------- | -------------------------- |
3713e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3714e41f4b71Sopenharmony_ci
3715e41f4b71Sopenharmony_ci**Example**
3716e41f4b71Sopenharmony_ci
3717e41f4b71Sopenharmony_ci```ts
3718e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3719e41f4b71Sopenharmony_ci
3720e41f4b71Sopenharmony_ciaVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
3721e41f4b71Sopenharmony_ci  console.info('getCurrentItem successfully');
3722e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3723e41f4b71Sopenharmony_ci  console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3724e41f4b71Sopenharmony_ci});
3725e41f4b71Sopenharmony_ci```
3726e41f4b71Sopenharmony_ci
3727e41f4b71Sopenharmony_ci### getValidCommands<sup>11+</sup>
3728e41f4b71Sopenharmony_ci
3729e41f4b71Sopenharmony_cigetValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void
3730e41f4b71Sopenharmony_ci
3731e41f4b71Sopenharmony_ciObtains the supported commands. This API uses an asynchronous callback to return the result.
3732e41f4b71Sopenharmony_ci
3733e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3734e41f4b71Sopenharmony_ci
3735e41f4b71Sopenharmony_ci**Parameters**
3736e41f4b71Sopenharmony_ci
3737e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                     |
3738e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ----------------------------------------------- |
3739e41f4b71Sopenharmony_ci| callback | Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)> | Yes       | Callback used to return the supported commands. |
3740e41f4b71Sopenharmony_ci
3741e41f4b71Sopenharmony_ci**Error codes**
3742e41f4b71Sopenharmony_ci
3743e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3744e41f4b71Sopenharmony_ci
3745e41f4b71Sopenharmony_ci| ID      | Error Message              |
3746e41f4b71Sopenharmony_ci| ------- | -------------------------- |
3747e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3748e41f4b71Sopenharmony_ci
3749e41f4b71Sopenharmony_ci**Example**
3750e41f4b71Sopenharmony_ci
3751e41f4b71Sopenharmony_ci```ts
3752e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3753e41f4b71Sopenharmony_ci
3754e41f4b71Sopenharmony_ciaVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => {
3755e41f4b71Sopenharmony_ci  if (err) {
3756e41f4b71Sopenharmony_ci    console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3757e41f4b71Sopenharmony_ci  } else {
3758e41f4b71Sopenharmony_ci    console.info('getValidCommands successfully');
3759e41f4b71Sopenharmony_ci  }
3760e41f4b71Sopenharmony_ci});
3761e41f4b71Sopenharmony_ci```
3762e41f4b71Sopenharmony_ci
3763e41f4b71Sopenharmony_ci### getValidCommands<sup>11+</sup>
3764e41f4b71Sopenharmony_ci
3765e41f4b71Sopenharmony_cigetValidCommands(): Promise<Array\<AVCastControlCommandType>>
3766e41f4b71Sopenharmony_ci
3767e41f4b71Sopenharmony_ciObtains the supported commands. This API uses a promise to return the result.
3768e41f4b71Sopenharmony_ci
3769e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3770e41f4b71Sopenharmony_ci
3771e41f4b71Sopenharmony_ci**Return value**
3772e41f4b71Sopenharmony_ci
3773e41f4b71Sopenharmony_ci| Type                                                         | Description                                    |
3774e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ---------------------------------------------- |
3775e41f4b71Sopenharmony_ci| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise used to return the supported commands. |
3776e41f4b71Sopenharmony_ci
3777e41f4b71Sopenharmony_ci**Error codes**
3778e41f4b71Sopenharmony_ci
3779e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3780e41f4b71Sopenharmony_ci
3781e41f4b71Sopenharmony_ci| ID      | Error Message              |
3782e41f4b71Sopenharmony_ci| ------- | -------------------------- |
3783e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3784e41f4b71Sopenharmony_ci
3785e41f4b71Sopenharmony_ci**Example**
3786e41f4b71Sopenharmony_ci
3787e41f4b71Sopenharmony_ci```ts
3788e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3789e41f4b71Sopenharmony_ci
3790e41f4b71Sopenharmony_ciaVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => {
3791e41f4b71Sopenharmony_ci  console.info('getValidCommands successfully');
3792e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3793e41f4b71Sopenharmony_ci  console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3794e41f4b71Sopenharmony_ci});
3795e41f4b71Sopenharmony_ci```
3796e41f4b71Sopenharmony_ci
3797e41f4b71Sopenharmony_ci### processMediaKeyResponse<sup>12+</sup>
3798e41f4b71Sopenharmony_ci
3799e41f4b71Sopenharmony_ciprocessMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void>
3800e41f4b71Sopenharmony_ci
3801e41f4b71Sopenharmony_ciProcesses the response to a media key request during online DRM resource projection. This API uses a promise to return the result.
3802e41f4b71Sopenharmony_ci
3803e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3804e41f4b71Sopenharmony_ci
3805e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3806e41f4b71Sopenharmony_ci
3807e41f4b71Sopenharmony_ci**Parameters**
3808e41f4b71Sopenharmony_ci
3809e41f4b71Sopenharmony_ci| Name     | Type       | Mandatory | Description                        |
3810e41f4b71Sopenharmony_ci| -------- | ---------- | --------- | ---------------------------------- |
3811e41f4b71Sopenharmony_ci| assetId  | string     | Yes       | Media asset ID.                    |
3812e41f4b71Sopenharmony_ci| response | Uint8Array | Yes       | Response to the media key request. |
3813e41f4b71Sopenharmony_ci
3814e41f4b71Sopenharmony_ci**Return value**
3815e41f4b71Sopenharmony_ci
3816e41f4b71Sopenharmony_ci| Type           | Description                                                  |
3817e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
3818e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the response is processed successfully, no result is returned. Otherwise, an error object is returned. |
3819e41f4b71Sopenharmony_ci
3820e41f4b71Sopenharmony_ci**Error codes**
3821e41f4b71Sopenharmony_ci
3822e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3823e41f4b71Sopenharmony_ci
3824e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3825e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3826e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3827e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3828e41f4b71Sopenharmony_ci
3829e41f4b71Sopenharmony_ci**Example**
3830e41f4b71Sopenharmony_ci
3831e41f4b71Sopenharmony_ci```ts
3832e41f4b71Sopenharmony_cilet keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
3833e41f4b71Sopenharmony_ci  // Obtain the DRM URL based on the asset ID.
3834e41f4b71Sopenharmony_ci  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
3835e41f4b71Sopenharmony_ci  // Obtain a media key from the server. Assign a value based on service requirements.
3836e41f4b71Sopenharmony_ci  let licenseResponseData: Uint8Array = new Uint8Array();
3837e41f4b71Sopenharmony_ci  console.info(`Succeeded in get license by ${drmUrl}.`);
3838e41f4b71Sopenharmony_ci  aVCastController.processMediaKeyResponse(assetId, licenseResponseData);
3839e41f4b71Sopenharmony_ci}
3840e41f4b71Sopenharmony_ci```
3841e41f4b71Sopenharmony_ci
3842e41f4b71Sopenharmony_ci### release<sup>11+</sup>
3843e41f4b71Sopenharmony_ci
3844e41f4b71Sopenharmony_cirelease(callback: AsyncCallback\<void>): void
3845e41f4b71Sopenharmony_ci
3846e41f4b71Sopenharmony_ciReleases this cast controller. This API uses an asynchronous callback to return the result.
3847e41f4b71Sopenharmony_ci
3848e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3849e41f4b71Sopenharmony_ci
3850e41f4b71Sopenharmony_ci**Parameters**
3851e41f4b71Sopenharmony_ci
3852e41f4b71Sopenharmony_ci| Name     | Type                 | Mandatory | Description                                                  |
3853e41f4b71Sopenharmony_ci| -------- | -------------------- | --------- | ------------------------------------------------------------ |
3854e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the controller is released, **err** is **undefined**; otherwise, **err** is an error object. |
3855e41f4b71Sopenharmony_ci
3856e41f4b71Sopenharmony_ci**Error codes**
3857e41f4b71Sopenharmony_ci
3858e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3859e41f4b71Sopenharmony_ci
3860e41f4b71Sopenharmony_ci| ID      | Error Message              |
3861e41f4b71Sopenharmony_ci| ------- | -------------------------- |
3862e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3863e41f4b71Sopenharmony_ci
3864e41f4b71Sopenharmony_ci**Example**
3865e41f4b71Sopenharmony_ci
3866e41f4b71Sopenharmony_ci```ts
3867e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3868e41f4b71Sopenharmony_ci
3869e41f4b71Sopenharmony_ciaVCastController.release((err: BusinessError) => {
3870e41f4b71Sopenharmony_ci  if (err) {
3871e41f4b71Sopenharmony_ci    console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
3872e41f4b71Sopenharmony_ci  } else {
3873e41f4b71Sopenharmony_ci    console.info('release successfully');
3874e41f4b71Sopenharmony_ci  }
3875e41f4b71Sopenharmony_ci});
3876e41f4b71Sopenharmony_ci```
3877e41f4b71Sopenharmony_ci
3878e41f4b71Sopenharmony_ci### release<sup>11+</sup>
3879e41f4b71Sopenharmony_ci
3880e41f4b71Sopenharmony_cirelease(): Promise\<void>
3881e41f4b71Sopenharmony_ci
3882e41f4b71Sopenharmony_ciReleases this cast controller. This API uses a promise to return the result.
3883e41f4b71Sopenharmony_ci
3884e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3885e41f4b71Sopenharmony_ci
3886e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3887e41f4b71Sopenharmony_ci
3888e41f4b71Sopenharmony_ci**Return value**
3889e41f4b71Sopenharmony_ci
3890e41f4b71Sopenharmony_ci| Type           | Description                                                  |
3891e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
3892e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the controller is released, no value is returned; otherwise, an error object is returned. |
3893e41f4b71Sopenharmony_ci
3894e41f4b71Sopenharmony_ci**Error codes**
3895e41f4b71Sopenharmony_ci
3896e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3897e41f4b71Sopenharmony_ci
3898e41f4b71Sopenharmony_ci| ID      | Error Message              |
3899e41f4b71Sopenharmony_ci| ------- | -------------------------- |
3900e41f4b71Sopenharmony_ci| 6600101 | Session service exception. |
3901e41f4b71Sopenharmony_ci
3902e41f4b71Sopenharmony_ci**Example**
3903e41f4b71Sopenharmony_ci
3904e41f4b71Sopenharmony_ci```ts
3905e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3906e41f4b71Sopenharmony_ci
3907e41f4b71Sopenharmony_ciaVCastController.release().then(() => {
3908e41f4b71Sopenharmony_ci  console.info('release successfully');
3909e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
3910e41f4b71Sopenharmony_ci  console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
3911e41f4b71Sopenharmony_ci});
3912e41f4b71Sopenharmony_ci
3913e41f4b71Sopenharmony_ci```
3914e41f4b71Sopenharmony_ci
3915e41f4b71Sopenharmony_ci### on('playbackStateChange')<sup>10+</sup>
3916e41f4b71Sopenharmony_ci
3917e41f4b71Sopenharmony_cion(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void
3918e41f4b71Sopenharmony_ci
3919e41f4b71Sopenharmony_ciSubscribes to playback state change events.
3920e41f4b71Sopenharmony_ci
3921e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3922e41f4b71Sopenharmony_ci
3923e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3924e41f4b71Sopenharmony_ci
3925e41f4b71Sopenharmony_ci**Parameters**
3926e41f4b71Sopenharmony_ci
3927e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
3928e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
3929e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'playbackStateChange'** is triggered when the playback state changes. |
3930e41f4b71Sopenharmony_ci| 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. |
3931e41f4b71Sopenharmony_ci| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void       | Yes       | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state. |
3932e41f4b71Sopenharmony_ci
3933e41f4b71Sopenharmony_ci**Error codes**
3934e41f4b71Sopenharmony_ci
3935e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3936e41f4b71Sopenharmony_ci
3937e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3938e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3939e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3940e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3941e41f4b71Sopenharmony_ci
3942e41f4b71Sopenharmony_ci**Example**
3943e41f4b71Sopenharmony_ci
3944e41f4b71Sopenharmony_ci```ts
3945e41f4b71Sopenharmony_ciaVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
3946e41f4b71Sopenharmony_ci  console.info(`on playbackStateChange state : ${playbackState.state}`);
3947e41f4b71Sopenharmony_ci});
3948e41f4b71Sopenharmony_ci
3949e41f4b71Sopenharmony_cilet playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode'];
3950e41f4b71Sopenharmony_ciaVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
3951e41f4b71Sopenharmony_ci  console.info(`on playbackStateChange state : ${playbackState.state}`);
3952e41f4b71Sopenharmony_ci});
3953e41f4b71Sopenharmony_ci```
3954e41f4b71Sopenharmony_ci
3955e41f4b71Sopenharmony_ci### off('playbackStateChange')<sup>10+</sup>
3956e41f4b71Sopenharmony_ci
3957e41f4b71Sopenharmony_cioff(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void
3958e41f4b71Sopenharmony_ci
3959e41f4b71Sopenharmony_ciUnsubscribes from playback state change events. This API is called by the controller.
3960e41f4b71Sopenharmony_ci
3961e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3962e41f4b71Sopenharmony_ci
3963e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3964e41f4b71Sopenharmony_ci
3965e41f4b71Sopenharmony_ci**Parameters**
3966e41f4b71Sopenharmony_ci
3967e41f4b71Sopenharmony_ci| Name     | Type                                                   | Mandatory | Description                                                  |
3968e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
3969e41f4b71Sopenharmony_ci| type     | string                                                 | Yes       | Event type, which is **'playbackStateChange'** in this case. |
3970e41f4b71Sopenharmony_ci| 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. |
3971e41f4b71Sopenharmony_ci
3972e41f4b71Sopenharmony_ci**Error codes**
3973e41f4b71Sopenharmony_ci
3974e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3975e41f4b71Sopenharmony_ci
3976e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
3977e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
3978e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3979e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
3980e41f4b71Sopenharmony_ci
3981e41f4b71Sopenharmony_ci**Example**
3982e41f4b71Sopenharmony_ci
3983e41f4b71Sopenharmony_ci```ts
3984e41f4b71Sopenharmony_ciaVCastController.off('playbackStateChange');
3985e41f4b71Sopenharmony_ci```
3986e41f4b71Sopenharmony_ci
3987e41f4b71Sopenharmony_ci### on('mediaItemChange')<sup>10+</sup>
3988e41f4b71Sopenharmony_ci
3989e41f4b71Sopenharmony_cion(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
3990e41f4b71Sopenharmony_ci
3991e41f4b71Sopenharmony_ciSubscribes to media asset change events.
3992e41f4b71Sopenharmony_ci
3993e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3994e41f4b71Sopenharmony_ci
3995e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3996e41f4b71Sopenharmony_ci
3997e41f4b71Sopenharmony_ci**Parameters**
3998e41f4b71Sopenharmony_ci
3999e41f4b71Sopenharmony_ci| Name     | Type                                              | Mandatory | Description                                                  |
4000e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | --------- | ------------------------------------------------------------ |
4001e41f4b71Sopenharmony_ci| type     | string                                            | Yes       | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes. |
4002e41f4b71Sopenharmony_ci| callback | (callback: [AVQueueItem](#avqueueitem10)) => void | Yes       | Callback used for subscription. **AVQueueItem** is the media asset that is being played. |
4003e41f4b71Sopenharmony_ci
4004e41f4b71Sopenharmony_ci**Error codes**
4005e41f4b71Sopenharmony_ci
4006e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4007e41f4b71Sopenharmony_ci
4008e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4009e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4010e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4011e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4012e41f4b71Sopenharmony_ci
4013e41f4b71Sopenharmony_ci**Example**
4014e41f4b71Sopenharmony_ci
4015e41f4b71Sopenharmony_ci```ts
4016e41f4b71Sopenharmony_ciaVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
4017e41f4b71Sopenharmony_ci  console.info(`on mediaItemChange state : ${item.itemId}`);
4018e41f4b71Sopenharmony_ci});
4019e41f4b71Sopenharmony_ci```
4020e41f4b71Sopenharmony_ci
4021e41f4b71Sopenharmony_ci### off('mediaItemChange')<sup>10+</sup>
4022e41f4b71Sopenharmony_ci
4023e41f4b71Sopenharmony_cioff(type: 'mediaItemChange'): void
4024e41f4b71Sopenharmony_ci
4025e41f4b71Sopenharmony_ciUnsubscribes from media asset change events.
4026e41f4b71Sopenharmony_ci
4027e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4028e41f4b71Sopenharmony_ci
4029e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4030e41f4b71Sopenharmony_ci
4031e41f4b71Sopenharmony_ci**Parameters**
4032e41f4b71Sopenharmony_ci
4033e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                              |
4034e41f4b71Sopenharmony_ci| ---- | ------ | --------- | -------------------------------------------------------- |
4035e41f4b71Sopenharmony_ci| type | string | Yes       | Event type, which is **'mediaItemChange'** in this case. |
4036e41f4b71Sopenharmony_ci
4037e41f4b71Sopenharmony_ci**Error codes**
4038e41f4b71Sopenharmony_ci
4039e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4040e41f4b71Sopenharmony_ci
4041e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4042e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4043e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4044e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4045e41f4b71Sopenharmony_ci
4046e41f4b71Sopenharmony_ci**Example**
4047e41f4b71Sopenharmony_ci
4048e41f4b71Sopenharmony_ci```ts
4049e41f4b71Sopenharmony_ciaVCastController.off('mediaItemChange');
4050e41f4b71Sopenharmony_ci```
4051e41f4b71Sopenharmony_ci
4052e41f4b71Sopenharmony_ci### on('playNext')<sup>10+</sup>
4053e41f4b71Sopenharmony_ci
4054e41f4b71Sopenharmony_cion(type: 'playNext', callback: Callback\<void>): void
4055e41f4b71Sopenharmony_ci
4056e41f4b71Sopenharmony_ciSubscribes to playNext command events.
4057e41f4b71Sopenharmony_ci
4058e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4059e41f4b71Sopenharmony_ci
4060e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4061e41f4b71Sopenharmony_ci
4062e41f4b71Sopenharmony_ci**Parameters**
4063e41f4b71Sopenharmony_ci
4064e41f4b71Sopenharmony_ci| Name     | Type             | Mandatory | Description                                                  |
4065e41f4b71Sopenharmony_ci| -------- | ---------------- | --------- | ------------------------------------------------------------ |
4066e41f4b71Sopenharmony_ci| type     | string           | Yes       | Event type. The event **'playNext'** is triggered when the command for playing the next item is received. |
4067e41f4b71Sopenharmony_ci| callback | Callback\<void\> | Yes       | Callback used to return the result.                          |
4068e41f4b71Sopenharmony_ci
4069e41f4b71Sopenharmony_ci**Error codes**
4070e41f4b71Sopenharmony_ci
4071e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4072e41f4b71Sopenharmony_ci
4073e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4074e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4075e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4076e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4077e41f4b71Sopenharmony_ci
4078e41f4b71Sopenharmony_ci**Example**
4079e41f4b71Sopenharmony_ci
4080e41f4b71Sopenharmony_ci```ts
4081e41f4b71Sopenharmony_ciaVCastController.on('playNext', () => {
4082e41f4b71Sopenharmony_ci  console.info('on playNext');
4083e41f4b71Sopenharmony_ci});
4084e41f4b71Sopenharmony_ci```
4085e41f4b71Sopenharmony_ci
4086e41f4b71Sopenharmony_ci### off('playNext')<sup>10+</sup>
4087e41f4b71Sopenharmony_ci
4088e41f4b71Sopenharmony_cioff(type: 'playNext'): void
4089e41f4b71Sopenharmony_ci
4090e41f4b71Sopenharmony_ciUnsubscribes from playNext command events.
4091e41f4b71Sopenharmony_ci
4092e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4093e41f4b71Sopenharmony_ci
4094e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4095e41f4b71Sopenharmony_ci
4096e41f4b71Sopenharmony_ci**Parameters**
4097e41f4b71Sopenharmony_ci
4098e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                       |
4099e41f4b71Sopenharmony_ci| ---- | ------ | --------- | ------------------------------------------------- |
4100e41f4b71Sopenharmony_ci| type | string | Yes       | Event type, which is **'playNext'** in this case. |
4101e41f4b71Sopenharmony_ci
4102e41f4b71Sopenharmony_ci**Error codes**
4103e41f4b71Sopenharmony_ci
4104e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4105e41f4b71Sopenharmony_ci
4106e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4107e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4108e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4109e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4110e41f4b71Sopenharmony_ci
4111e41f4b71Sopenharmony_ci**Example**
4112e41f4b71Sopenharmony_ci
4113e41f4b71Sopenharmony_ci```ts
4114e41f4b71Sopenharmony_ciaVCastController.off('playNext');
4115e41f4b71Sopenharmony_ci```
4116e41f4b71Sopenharmony_ci
4117e41f4b71Sopenharmony_ci### on('playPrevious')<sup>10+</sup>
4118e41f4b71Sopenharmony_ci
4119e41f4b71Sopenharmony_cion(type: 'playPrevious', callback: Callback\<void>): void
4120e41f4b71Sopenharmony_ci
4121e41f4b71Sopenharmony_ciSubscribes to playPrevious command events.
4122e41f4b71Sopenharmony_ci
4123e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4124e41f4b71Sopenharmony_ci
4125e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4126e41f4b71Sopenharmony_ci
4127e41f4b71Sopenharmony_ci**Parameters**
4128e41f4b71Sopenharmony_ci
4129e41f4b71Sopenharmony_ci| Name     | Type             | Mandatory | Description                                                  |
4130e41f4b71Sopenharmony_ci| -------- | ---------------- | --------- | ------------------------------------------------------------ |
4131e41f4b71Sopenharmony_ci| type     | string           | Yes       | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received. |
4132e41f4b71Sopenharmony_ci| callback | Callback\<void\> | Yes       | Callback used to return the result.                          |
4133e41f4b71Sopenharmony_ci
4134e41f4b71Sopenharmony_ci**Error codes**
4135e41f4b71Sopenharmony_ci
4136e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4137e41f4b71Sopenharmony_ci
4138e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4139e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4140e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4141e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4142e41f4b71Sopenharmony_ci
4143e41f4b71Sopenharmony_ci**Example**
4144e41f4b71Sopenharmony_ci
4145e41f4b71Sopenharmony_ci```ts
4146e41f4b71Sopenharmony_ciaVCastController.on('playPrevious', () => {
4147e41f4b71Sopenharmony_ci  console.info('on playPrevious');
4148e41f4b71Sopenharmony_ci});
4149e41f4b71Sopenharmony_ci```
4150e41f4b71Sopenharmony_ci
4151e41f4b71Sopenharmony_ci### off('playPrevious')<sup>10+</sup>
4152e41f4b71Sopenharmony_ci
4153e41f4b71Sopenharmony_cioff(type: 'playPrevious'): void
4154e41f4b71Sopenharmony_ci
4155e41f4b71Sopenharmony_ciUnsubscribes from playPrevious command events.
4156e41f4b71Sopenharmony_ci
4157e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4158e41f4b71Sopenharmony_ci
4159e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4160e41f4b71Sopenharmony_ci
4161e41f4b71Sopenharmony_ci**Parameters**
4162e41f4b71Sopenharmony_ci
4163e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                           |
4164e41f4b71Sopenharmony_ci| ---- | ------ | --------- | ----------------------------------------------------- |
4165e41f4b71Sopenharmony_ci| type | string | Yes       | Event type, which is **'playPrevious'** in this case. |
4166e41f4b71Sopenharmony_ci
4167e41f4b71Sopenharmony_ci**Error codes**
4168e41f4b71Sopenharmony_ci
4169e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4170e41f4b71Sopenharmony_ci
4171e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4172e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4173e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4174e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4175e41f4b71Sopenharmony_ci
4176e41f4b71Sopenharmony_ci**Example**
4177e41f4b71Sopenharmony_ci
4178e41f4b71Sopenharmony_ci```ts
4179e41f4b71Sopenharmony_ciaVCastController.off('playPrevious');
4180e41f4b71Sopenharmony_ci```
4181e41f4b71Sopenharmony_ci
4182e41f4b71Sopenharmony_ci### on('requestPlay')<sup>11+</sup>
4183e41f4b71Sopenharmony_ci
4184e41f4b71Sopenharmony_cion(type: 'requestPlay', callback: Callback\<AVQueueItem>): void
4185e41f4b71Sopenharmony_ci
4186e41f4b71Sopenharmony_ciSubscribes to playback request events.
4187e41f4b71Sopenharmony_ci
4188e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4189e41f4b71Sopenharmony_ci
4190e41f4b71Sopenharmony_ci**Parameters**
4191e41f4b71Sopenharmony_ci
4192e41f4b71Sopenharmony_ci| Name     | Type                                           | Mandatory | Description                                                  |
4193e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
4194e41f4b71Sopenharmony_ci| type     | string                                         | Yes       | Event type. The event **'requestPlay'** is triggered when a playback request is received. |
4195e41f4b71Sopenharmony_ci| callback | (state: [AVQueueItem](#avqueueitem10)) => void | Yes       | Callback used for subscription. **AVQueueItem** is the media asset that is being played. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. |
4196e41f4b71Sopenharmony_ci
4197e41f4b71Sopenharmony_ci**Error codes**
4198e41f4b71Sopenharmony_ci
4199e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4200e41f4b71Sopenharmony_ci
4201e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4202e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4203e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4204e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4205e41f4b71Sopenharmony_ci
4206e41f4b71Sopenharmony_ci**Example**
4207e41f4b71Sopenharmony_ci
4208e41f4b71Sopenharmony_ci```ts
4209e41f4b71Sopenharmony_ciaVCastController.on('requestPlay', (item: avSession.AVQueueItem) => {
4210e41f4b71Sopenharmony_ci  console.info(`on requestPlay state : ${item.itemId}`);
4211e41f4b71Sopenharmony_ci});
4212e41f4b71Sopenharmony_ci```
4213e41f4b71Sopenharmony_ci
4214e41f4b71Sopenharmony_ci### off('requestPlay')<sup>11+</sup>
4215e41f4b71Sopenharmony_ci
4216e41f4b71Sopenharmony_cioff(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void
4217e41f4b71Sopenharmony_ci
4218e41f4b71Sopenharmony_ciUnsubscribes from playback request events.
4219e41f4b71Sopenharmony_ci
4220e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4221e41f4b71Sopenharmony_ci
4222e41f4b71Sopenharmony_ci**Parameters**
4223e41f4b71Sopenharmony_ci
4224e41f4b71Sopenharmony_ci| Name     | Type                                           | Mandatory | Description                                                  |
4225e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
4226e41f4b71Sopenharmony_ci| type     | string                                         | Yes       | Event type, which is **'requestPlay'** in this case.         |
4227e41f4b71Sopenharmony_ci| callback | (state: [AVQueueItem](#avqueueitem10)) => void | No        | Callback used for unsubscription. **AVQueueItem** is the media asset that is being played. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
4228e41f4b71Sopenharmony_ci
4229e41f4b71Sopenharmony_ci**Error codes**
4230e41f4b71Sopenharmony_ci
4231e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4232e41f4b71Sopenharmony_ci
4233e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4234e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4235e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4236e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4237e41f4b71Sopenharmony_ci
4238e41f4b71Sopenharmony_ci**Example**
4239e41f4b71Sopenharmony_ci
4240e41f4b71Sopenharmony_ci```ts
4241e41f4b71Sopenharmony_ciaVCastController.off('requestPlay');
4242e41f4b71Sopenharmony_ci```
4243e41f4b71Sopenharmony_ci
4244e41f4b71Sopenharmony_ci### on('endOfStream')<sup>11+</sup>
4245e41f4b71Sopenharmony_ci
4246e41f4b71Sopenharmony_cion(type: 'endOfStream', callback: Callback\<void>): void
4247e41f4b71Sopenharmony_ci
4248e41f4b71Sopenharmony_ciSubscribes to playback end events.
4249e41f4b71Sopenharmony_ci
4250e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4251e41f4b71Sopenharmony_ci
4252e41f4b71Sopenharmony_ci**Parameters**
4253e41f4b71Sopenharmony_ci
4254e41f4b71Sopenharmony_ci| Name     | Type             | Mandatory | Description                                                  |
4255e41f4b71Sopenharmony_ci| -------- | ---------------- | --------- | ------------------------------------------------------------ |
4256e41f4b71Sopenharmony_ci| type     | string           | Yes       | Event type. The event **'endOfStream'** is triggered when the playback operation is complete. |
4257e41f4b71Sopenharmony_ci| callback | Callback\<void\> | Yes       | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. |
4258e41f4b71Sopenharmony_ci
4259e41f4b71Sopenharmony_ci**Error codes**
4260e41f4b71Sopenharmony_ci
4261e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4262e41f4b71Sopenharmony_ci
4263e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4264e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4265e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4266e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4267e41f4b71Sopenharmony_ci
4268e41f4b71Sopenharmony_ci**Example**
4269e41f4b71Sopenharmony_ci
4270e41f4b71Sopenharmony_ci```ts
4271e41f4b71Sopenharmony_ciaVCastController.on('endOfStream', () => {
4272e41f4b71Sopenharmony_ci  console.info('on endOfStream');
4273e41f4b71Sopenharmony_ci});
4274e41f4b71Sopenharmony_ci```
4275e41f4b71Sopenharmony_ci
4276e41f4b71Sopenharmony_ci### off('endOfStream')<sup>11+</sup>
4277e41f4b71Sopenharmony_ci
4278e41f4b71Sopenharmony_cioff(type: 'endOfStream', callback?: Callback\<void>): void
4279e41f4b71Sopenharmony_ci
4280e41f4b71Sopenharmony_ciUnsubscribes from the playback end events.
4281e41f4b71Sopenharmony_ci
4282e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4283e41f4b71Sopenharmony_ci
4284e41f4b71Sopenharmony_ci**Parameters**
4285e41f4b71Sopenharmony_ci
4286e41f4b71Sopenharmony_ci| Name     | Type             | Mandatory | Description                                                  |
4287e41f4b71Sopenharmony_ci| -------- | ---------------- | --------- | ------------------------------------------------------------ |
4288e41f4b71Sopenharmony_ci| type     | string           | Yes       | Event type, which is **'endOfStream'** in this case.         |
4289e41f4b71Sopenharmony_ci| callback | Callback\<void\> | No        | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
4290e41f4b71Sopenharmony_ci
4291e41f4b71Sopenharmony_ci**Error codes**
4292e41f4b71Sopenharmony_ci
4293e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4294e41f4b71Sopenharmony_ci
4295e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4296e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4297e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4298e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4299e41f4b71Sopenharmony_ci
4300e41f4b71Sopenharmony_ci**Example**
4301e41f4b71Sopenharmony_ci
4302e41f4b71Sopenharmony_ci```ts
4303e41f4b71Sopenharmony_ciaVCastController.off('endOfStream');
4304e41f4b71Sopenharmony_ci```
4305e41f4b71Sopenharmony_ci
4306e41f4b71Sopenharmony_ci### on('seekDone')<sup>10+</sup>
4307e41f4b71Sopenharmony_ci
4308e41f4b71Sopenharmony_cion(type: 'seekDone', callback: Callback\<number>): void
4309e41f4b71Sopenharmony_ci
4310e41f4b71Sopenharmony_ciSubscribes to seek done events.
4311e41f4b71Sopenharmony_ci
4312e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4313e41f4b71Sopenharmony_ci
4314e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4315e41f4b71Sopenharmony_ci
4316e41f4b71Sopenharmony_ci**Parameters**
4317e41f4b71Sopenharmony_ci
4318e41f4b71Sopenharmony_ci| Name     | Type               | Mandatory | Description                                                  |
4319e41f4b71Sopenharmony_ci| -------- | ------------------ | --------- | ------------------------------------------------------------ |
4320e41f4b71Sopenharmony_ci| type     | string             | Yes       | Event type. The event **'seekDone'** is triggered when the seek operation is complete. |
4321e41f4b71Sopenharmony_ci| callback | Callback\<number\> | Yes       | Callback used to return the position after the seek operation. |
4322e41f4b71Sopenharmony_ci
4323e41f4b71Sopenharmony_ci**Error codes**
4324e41f4b71Sopenharmony_ci
4325e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4326e41f4b71Sopenharmony_ci
4327e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4328e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4329e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4330e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4331e41f4b71Sopenharmony_ci
4332e41f4b71Sopenharmony_ci**Example**
4333e41f4b71Sopenharmony_ci
4334e41f4b71Sopenharmony_ci```ts
4335e41f4b71Sopenharmony_ciaVCastController.on('seekDone', (pos: number) => {
4336e41f4b71Sopenharmony_ci  console.info(`on seekDone pos: ${pos} `);
4337e41f4b71Sopenharmony_ci});
4338e41f4b71Sopenharmony_ci```
4339e41f4b71Sopenharmony_ci
4340e41f4b71Sopenharmony_ci### off('seekDone')<sup>10+</sup>
4341e41f4b71Sopenharmony_ci
4342e41f4b71Sopenharmony_cioff(type: 'seekDone'): void
4343e41f4b71Sopenharmony_ci
4344e41f4b71Sopenharmony_ciUnsubscribes from the seek done events.
4345e41f4b71Sopenharmony_ci
4346e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4347e41f4b71Sopenharmony_ci
4348e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4349e41f4b71Sopenharmony_ci
4350e41f4b71Sopenharmony_ci**Parameters**
4351e41f4b71Sopenharmony_ci
4352e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                       |
4353e41f4b71Sopenharmony_ci| ---- | ------ | --------- | ------------------------------------------------- |
4354e41f4b71Sopenharmony_ci| type | string | Yes       | Event type, which is **'seekDone'** in this case. |
4355e41f4b71Sopenharmony_ci
4356e41f4b71Sopenharmony_ci**Error codes**
4357e41f4b71Sopenharmony_ci
4358e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4359e41f4b71Sopenharmony_ci
4360e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4361e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4362e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4363e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4364e41f4b71Sopenharmony_ci
4365e41f4b71Sopenharmony_ci**Example**
4366e41f4b71Sopenharmony_ci
4367e41f4b71Sopenharmony_ci```ts
4368e41f4b71Sopenharmony_ciaVCastController.off('seekDone');
4369e41f4b71Sopenharmony_ci```
4370e41f4b71Sopenharmony_ci
4371e41f4b71Sopenharmony_ci### on('validCommandChange')<sup>11+</sup>
4372e41f4b71Sopenharmony_ci
4373e41f4b71Sopenharmony_cion(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>)
4374e41f4b71Sopenharmony_ci
4375e41f4b71Sopenharmony_ciSubscribes to valid command change events.
4376e41f4b71Sopenharmony_ci
4377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4378e41f4b71Sopenharmony_ci
4379e41f4b71Sopenharmony_ci**Parameters**
4380e41f4b71Sopenharmony_ci
4381e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
4382e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4383e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes. |
4384e41f4b71Sopenharmony_ci| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | Yes       | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. |
4385e41f4b71Sopenharmony_ci
4386e41f4b71Sopenharmony_ci**Error codes**
4387e41f4b71Sopenharmony_ci
4388e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4389e41f4b71Sopenharmony_ci
4390e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4391e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4392e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4393e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4394e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
4395e41f4b71Sopenharmony_ci
4396e41f4b71Sopenharmony_ci**Example**
4397e41f4b71Sopenharmony_ci
4398e41f4b71Sopenharmony_ci```ts
4399e41f4b71Sopenharmony_ciaVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => {
4400e41f4b71Sopenharmony_ci  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
4401e41f4b71Sopenharmony_ci  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
4402e41f4b71Sopenharmony_ci});
4403e41f4b71Sopenharmony_ci```
4404e41f4b71Sopenharmony_ci
4405e41f4b71Sopenharmony_ci### off('validCommandChange')<sup>11+</sup>
4406e41f4b71Sopenharmony_ci
4407e41f4b71Sopenharmony_cioff(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>)
4408e41f4b71Sopenharmony_ci
4409e41f4b71Sopenharmony_ciUnsubscribes from valid command change events. This API is called by the controller.
4410e41f4b71Sopenharmony_ci
4411e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4412e41f4b71Sopenharmony_ci
4413e41f4b71Sopenharmony_ci**Parameters**
4414e41f4b71Sopenharmony_ci
4415e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
4416e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4417e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type, which is **'validCommandChange'** in this case.  |
4418e41f4b71Sopenharmony_ci| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | 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. |
4419e41f4b71Sopenharmony_ci
4420e41f4b71Sopenharmony_ci**Error codes**
4421e41f4b71Sopenharmony_ci
4422e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4423e41f4b71Sopenharmony_ci
4424e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4425e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4426e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4427e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4428e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
4429e41f4b71Sopenharmony_ci
4430e41f4b71Sopenharmony_ci**Example**
4431e41f4b71Sopenharmony_ci
4432e41f4b71Sopenharmony_ci```ts
4433e41f4b71Sopenharmony_ciaVCastController.off('validCommandChange');
4434e41f4b71Sopenharmony_ci```
4435e41f4b71Sopenharmony_ci
4436e41f4b71Sopenharmony_ci### on('error')<sup>10+</sup>
4437e41f4b71Sopenharmony_ci
4438e41f4b71Sopenharmony_cion(type: 'error', callback: ErrorCallback): void
4439e41f4b71Sopenharmony_ci
4440e41f4b71Sopenharmony_ciSubscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control.
4441e41f4b71Sopenharmony_ci
4442e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4443e41f4b71Sopenharmony_ci
4444e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4445e41f4b71Sopenharmony_ci
4446e41f4b71Sopenharmony_ci**Parameters**
4447e41f4b71Sopenharmony_ci
4448e41f4b71Sopenharmony_ci| Name     | Type          | Mandatory | Description                                                  |
4449e41f4b71Sopenharmony_ci| -------- | ------------- | --------- | ------------------------------------------------------------ |
4450e41f4b71Sopenharmony_ci| type     | string        | Yes       | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system. |
4451e41f4b71Sopenharmony_ci| callback | ErrorCallback | Yes       | Callback used to return the error code ID and error message. |
4452e41f4b71Sopenharmony_ci
4453e41f4b71Sopenharmony_ci**Error codes**
4454e41f4b71Sopenharmony_ci
4455e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4456e41f4b71Sopenharmony_ci
4457e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4458e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4459e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4460e41f4b71Sopenharmony_ci| 5400101 | No memory.                                                   |
4461e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed.                                       |
4462e41f4b71Sopenharmony_ci| 5400103 | I/O error.                                                   |
4463e41f4b71Sopenharmony_ci| 5400104 | Time out.                                                    |
4464e41f4b71Sopenharmony_ci| 5400105 | Service died.                                                |
4465e41f4b71Sopenharmony_ci| 5400106 | Unsupport format.                                            |
4466e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4467e41f4b71Sopenharmony_ci
4468e41f4b71Sopenharmony_ci**Example**
4469e41f4b71Sopenharmony_ci
4470e41f4b71Sopenharmony_ci```ts
4471e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4472e41f4b71Sopenharmony_ci
4473e41f4b71Sopenharmony_ciaVCastController.on('error', (error: BusinessError) => {
4474e41f4b71Sopenharmony_ci  console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`)
4475e41f4b71Sopenharmony_ci})
4476e41f4b71Sopenharmony_ci```
4477e41f4b71Sopenharmony_ci
4478e41f4b71Sopenharmony_ci### off('error')<sup>10+</sup>
4479e41f4b71Sopenharmony_ci
4480e41f4b71Sopenharmony_cioff(type: 'error'): void
4481e41f4b71Sopenharmony_ci
4482e41f4b71Sopenharmony_ciUnsubscribes from remote AVPlayer errors.
4483e41f4b71Sopenharmony_ci
4484e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4485e41f4b71Sopenharmony_ci
4486e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4487e41f4b71Sopenharmony_ci
4488e41f4b71Sopenharmony_ci**Parameters**
4489e41f4b71Sopenharmony_ci
4490e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                    |
4491e41f4b71Sopenharmony_ci| ---- | ------ | --------- | ---------------------------------------------- |
4492e41f4b71Sopenharmony_ci| type | string | Yes       | Event type, which is **'error'** in this case. |
4493e41f4b71Sopenharmony_ci
4494e41f4b71Sopenharmony_ci**Error codes**
4495e41f4b71Sopenharmony_ci
4496e41f4b71Sopenharmony_ciFor details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4497e41f4b71Sopenharmony_ci
4498e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4499e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4500e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4501e41f4b71Sopenharmony_ci| 5400101 | No memory.                                                   |
4502e41f4b71Sopenharmony_ci| 5400102 | Operation not allowed.                                       |
4503e41f4b71Sopenharmony_ci| 5400103 | I/O error.                                                   |
4504e41f4b71Sopenharmony_ci| 5400104 | Time out.                                                    |
4505e41f4b71Sopenharmony_ci| 5400105 | Service died.                                                |
4506e41f4b71Sopenharmony_ci| 5400106 | Unsupport format.                                            |
4507e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4508e41f4b71Sopenharmony_ci
4509e41f4b71Sopenharmony_ci**Example**
4510e41f4b71Sopenharmony_ci
4511e41f4b71Sopenharmony_ci```ts
4512e41f4b71Sopenharmony_ciaVCastController.off('error')
4513e41f4b71Sopenharmony_ci```
4514e41f4b71Sopenharmony_ci
4515e41f4b71Sopenharmony_ci### on('keyRequest')<sup>12+</sup>
4516e41f4b71Sopenharmony_ci
4517e41f4b71Sopenharmony_cion(type: 'keyRequest', callback: KeyRequestCallback): void
4518e41f4b71Sopenharmony_ci
4519e41f4b71Sopenharmony_ciSubscribes to media key requests during the cast of online DRM resources.
4520e41f4b71Sopenharmony_ci
4521e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4522e41f4b71Sopenharmony_ci
4523e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4524e41f4b71Sopenharmony_ci
4525e41f4b71Sopenharmony_ci**Parameters**
4526e41f4b71Sopenharmony_ci
4527e41f4b71Sopenharmony_ci| Name     | Type                                        | Mandatory | Description                                                  |
4528e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | --------- | ------------------------------------------------------------ |
4529e41f4b71Sopenharmony_ci| type     | string                                      | Yes       | Event type. The event **'keyRequest'** is triggered when a media key request is required during the cast of online DRM resources. |
4530e41f4b71Sopenharmony_ci| callback | [KeyRequestCallback](#keyrequestcallback12) | Yes       | Callback used to request the media resources and media key.  |
4531e41f4b71Sopenharmony_ci
4532e41f4b71Sopenharmony_ci
4533e41f4b71Sopenharmony_ci**Error codes**
4534e41f4b71Sopenharmony_ci
4535e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4536e41f4b71Sopenharmony_ci
4537e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4538e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4539e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4540e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4541e41f4b71Sopenharmony_ci
4542e41f4b71Sopenharmony_ci**Example**
4543e41f4b71Sopenharmony_ci
4544e41f4b71Sopenharmony_ci```ts
4545e41f4b71Sopenharmony_cilet keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4546e41f4b71Sopenharmony_ci  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
4547e41f4b71Sopenharmony_ci}
4548e41f4b71Sopenharmony_ciaVCastController.on('keyRequest', keyRequestCallback);
4549e41f4b71Sopenharmony_ci```
4550e41f4b71Sopenharmony_ci### off('keyRequest')<sup>12+</sup>
4551e41f4b71Sopenharmony_ci
4552e41f4b71Sopenharmony_cioff(type: 'keyRequest', callback?: KeyRequestCallback): void
4553e41f4b71Sopenharmony_ci
4554e41f4b71Sopenharmony_ciUnsubscribes from media key requests during the cast of online DRM resources.
4555e41f4b71Sopenharmony_ci
4556e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4557e41f4b71Sopenharmony_ci
4558e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4559e41f4b71Sopenharmony_ci
4560e41f4b71Sopenharmony_ci**Parameters**
4561e41f4b71Sopenharmony_ci
4562e41f4b71Sopenharmony_ci| Name     | Type                                        | Mandatory | Description                                                  |
4563e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | --------- | ------------------------------------------------------------ |
4564e41f4b71Sopenharmony_ci| type     | string                                      | Yes       | Event type, which is **'keyRequest'** in this case.          |
4565e41f4b71Sopenharmony_ci| callback | [KeyRequestCallback](#keyrequestcallback12) | No        | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
4566e41f4b71Sopenharmony_ci
4567e41f4b71Sopenharmony_ci**Error codes**
4568e41f4b71Sopenharmony_ci
4569e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4570e41f4b71Sopenharmony_ci
4571e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
4572e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
4573e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4574e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
4575e41f4b71Sopenharmony_ci
4576e41f4b71Sopenharmony_ci**Example**
4577e41f4b71Sopenharmony_ci
4578e41f4b71Sopenharmony_ci```ts
4579e41f4b71Sopenharmony_ciaVCastController.off('keyRequest');
4580e41f4b71Sopenharmony_ci```
4581e41f4b71Sopenharmony_ci## KeyRequestCallback<sup>12+</sup>
4582e41f4b71Sopenharmony_citype KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void
4583e41f4b71Sopenharmony_ci
4584e41f4b71Sopenharmony_ciDescribes the callback invoked for the media key request event.
4585e41f4b71Sopenharmony_ci
4586e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4587e41f4b71Sopenharmony_ci
4588e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4589e41f4b71Sopenharmony_ci
4590e41f4b71Sopenharmony_ci**Parameters**
4591e41f4b71Sopenharmony_ci
4592e41f4b71Sopenharmony_ci| Name        | Type       | Mandatory | Description                            |
4593e41f4b71Sopenharmony_ci| ----------- | ---------- | --------- | -------------------------------------- |
4594e41f4b71Sopenharmony_ci| assetId     | string     | Yes       | Media asset ID.                        |
4595e41f4b71Sopenharmony_ci| requestData | Uint8Array | Yes       | Data carried in the media key request. |
4596e41f4b71Sopenharmony_ci
4597e41f4b71Sopenharmony_ci**Example**
4598e41f4b71Sopenharmony_ci<!--code_no_check-->
4599e41f4b71Sopenharmony_ci```ts
4600e41f4b71Sopenharmony_cilet keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4601e41f4b71Sopenharmony_ci  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
4602e41f4b71Sopenharmony_ci}
4603e41f4b71Sopenharmony_ci```
4604e41f4b71Sopenharmony_ci
4605e41f4b71Sopenharmony_ci## CastDisplayState<sup>12+</sup>
4606e41f4b71Sopenharmony_ci
4607e41f4b71Sopenharmony_ciEnumerates the states of the cast display.
4608e41f4b71Sopenharmony_ci
4609e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4610e41f4b71Sopenharmony_ci
4611e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
4612e41f4b71Sopenharmony_ci
4613e41f4b71Sopenharmony_ci| Name      | Value | Description                                                  |
4614e41f4b71Sopenharmony_ci| --------- | ----- | ------------------------------------------------------------ |
4615e41f4b71Sopenharmony_ci| STATE_OFF | 1     | The device is disconnected, and the extended screen does not display any content. |
4616e41f4b71Sopenharmony_ci| STATE_ON  | 2     | The device is connected, and the extended screen is available. |
4617e41f4b71Sopenharmony_ci
4618e41f4b71Sopenharmony_ci
4619e41f4b71Sopenharmony_ci## CastDisplayInfo<sup>12+</sup>
4620e41f4b71Sopenharmony_ci
4621e41f4b71Sopenharmony_ciDescribes the information about the cast display in the case of extended screens.
4622e41f4b71Sopenharmony_ci
4623e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4624e41f4b71Sopenharmony_ci
4625e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
4626e41f4b71Sopenharmony_ci
4627e41f4b71Sopenharmony_ci| Name   | Type                                    | Read-Only | Optional | Description                                                  |
4628e41f4b71Sopenharmony_ci| ------ | --------------------------------------- | --------- | -------- | ------------------------------------------------------------ |
4629e41f4b71Sopenharmony_ci| id     | number                                  | No        | No       | ID of the cast display. The value must be an integer.        |
4630e41f4b71Sopenharmony_ci| name   | string                                  | No        | No       | Name of the cast display.                                    |
4631e41f4b71Sopenharmony_ci| state  | [CastDisplayState](#castdisplaystate12) | No        | No       | State of the cast display.                                   |
4632e41f4b71Sopenharmony_ci| width  | number                                  | No        | No       | Screen width of the cast display, in px. The value must be an integer. |
4633e41f4b71Sopenharmony_ci| height | number                                  | No        | No       | Screen height of the cast display, in px. The value must be an integer. |
4634e41f4b71Sopenharmony_ci
4635e41f4b71Sopenharmony_ci## ConnectionState<sup>10+</sup>
4636e41f4b71Sopenharmony_ci
4637e41f4b71Sopenharmony_ciEnumerates the connection states.
4638e41f4b71Sopenharmony_ci
4639e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4640e41f4b71Sopenharmony_ci
4641e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4642e41f4b71Sopenharmony_ci
4643e41f4b71Sopenharmony_ci| Name               | Value | Description                 |
4644e41f4b71Sopenharmony_ci| ------------------ | ----- | --------------------------- |
4645e41f4b71Sopenharmony_ci| STATE_CONNECTING   | 0     | The device is connecting.   |
4646e41f4b71Sopenharmony_ci| STATE_CONNECTED    | 1     | The device is connected.    |
4647e41f4b71Sopenharmony_ci| STATE_DISCONNECTED | 6     | The device is disconnected. |
4648e41f4b71Sopenharmony_ci
4649e41f4b71Sopenharmony_ci## AVMetadata<sup>10+</sup>
4650e41f4b71Sopenharmony_ci
4651e41f4b71Sopenharmony_ciDescribes the media metadata.
4652e41f4b71Sopenharmony_ci
4653e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4654e41f4b71Sopenharmony_ci
4655e41f4b71Sopenharmony_ci| Name                        | Type                                                         | Mandatory | Description                                                  |
4656e41f4b71Sopenharmony_ci| --------------------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4657e41f4b71Sopenharmony_ci| assetId                     | string                                                       | Yes       | Media asset ID. It is the unique ID of a song and defined by the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4658e41f4b71Sopenharmony_ci| title                       | string                                                       | No        | Title.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4659e41f4b71Sopenharmony_ci| artist                      | string                                                       | No        | Artist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4660e41f4b71Sopenharmony_ci| author                      | string                                                       | No        | Author.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4661e41f4b71Sopenharmony_ci| avQueueName<sup>12+</sup>   | string                                                       | No        | Playlist name.                                               |
4662e41f4b71Sopenharmony_ci| avQueueId<sup>11+</sup>     | string                                                       | No        | Unique ID of the playlist.                                   |
4663e41f4b71Sopenharmony_ci| avQueueImage<sup>11+</sup>  | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | No        | Cover image of the playlist, which can be pixel data of an image or an image path (local path or Internet path).<br>When the data type configured by running **setAVMetadata** is **PixelMap**, the data obtained by calling **getAVMetadata** is a pixel map. When the configured data type is **string**, the data obtained is a URL. |
4664e41f4b71Sopenharmony_ci| album                       | string                                                       | No        | Album name.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4665e41f4b71Sopenharmony_ci| writer                      | string                                                       | No        | Writer.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4666e41f4b71Sopenharmony_ci| composer                    | string                                                       | No        | composer.                                                    |
4667e41f4b71Sopenharmony_ci| duration                    | number                                                       | No        | Media duration, in ms.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4668e41f4b71Sopenharmony_ci| mediaImage                  | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | No        | Pixel map or image path (local path or network path) of the image.<br>When the data type configured by running **setAVMetadata** is **PixelMap**, the data obtained by calling **getAVMetadata** is a pixel map. When the configured data type is **string**, the data obtained is a URL.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4669e41f4b71Sopenharmony_ci| publishDate                 | Date                                                         | No        | Release date.                                                |
4670e41f4b71Sopenharmony_ci| subtitle                    | string                                                       | No        | Subtitle.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4671e41f4b71Sopenharmony_ci| description                 | string                                                       | No        | Media description.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4672e41f4b71Sopenharmony_ci| lyric                       | string                                                       | No        | Lyrics. The application needs to combine the lyrics into a string. |
4673e41f4b71Sopenharmony_ci| previousAssetId             | string                                                       | No        | ID of the previous media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4674e41f4b71Sopenharmony_ci| nextAssetId                 | string                                                       | No        | ID of the next media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4675e41f4b71Sopenharmony_ci| filter<sup>11+</sup>        | number                                                       | No        | Protocol supported by the media session. The default value is **TYPE_CAST_PLUS_STREAM**. For details, see [ProtocolType](#protocoltype11).<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4676e41f4b71Sopenharmony_ci| drmSchemes<sup>12+</sup>    | Array\<string>                                               | No        | DRM scheme supported by the media session. The value is the UUID of the DRM scheme. |
4677e41f4b71Sopenharmony_ci| skipIntervals<sup>11+</sup> | [SkipIntervals](#skipintervals11)                            | No        | Fast-forward or rewind interval supported by the media session. The default value is **SECONDS_15**, that is, 15 seconds. |
4678e41f4b71Sopenharmony_ci| displayTags<sup>11+</sup>   | number                                                       | No        | Display tags of the media asset. For details, see [DisplayTag](#displaytag11). |
4679e41f4b71Sopenharmony_ci
4680e41f4b71Sopenharmony_ci## AVMediaDescription<sup>10+</sup>
4681e41f4b71Sopenharmony_ci
4682e41f4b71Sopenharmony_ciDescribes the attributes related to the media metadata in the playlist.
4683e41f4b71Sopenharmony_ci
4684e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4685e41f4b71Sopenharmony_ci
4686e41f4b71Sopenharmony_ci| Name                      | Type                      | Mandatory | Description                                                  |
4687e41f4b71Sopenharmony_ci| ------------------------- | ------------------------- | --------- | ------------------------------------------------------------ |
4688e41f4b71Sopenharmony_ci| assetId                   | string                    | Yes       | Media ID in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4689e41f4b71Sopenharmony_ci| title                     | string                    | No        | Name of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4690e41f4b71Sopenharmony_ci| subtitle                  | string                    | No        | Subname of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4691e41f4b71Sopenharmony_ci| description               | string                    | No        | Description of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4692e41f4b71Sopenharmony_ci| mediaImage                | image.PixelMap \| string  | No        | Pixel map of the image of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4693e41f4b71Sopenharmony_ci| extras                    | {[key: string]: Object}   | No        | Additional fields of the media asset in the playlist.        |
4694e41f4b71Sopenharmony_ci| mediaUri                  | string                    | No        | URI of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4695e41f4b71Sopenharmony_ci| mediaType                 | string                    | No        | Type of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4696e41f4b71Sopenharmony_ci| mediaSize                 | number                    | No        | Size of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4697e41f4b71Sopenharmony_ci| albumTitle                | string                    | No        | Album name of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4698e41f4b71Sopenharmony_ci| albumCoverUri             | string                    | No        | URI of the album title of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4699e41f4b71Sopenharmony_ci| lyricContent              | string                    | No        | Lyric content of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4700e41f4b71Sopenharmony_ci| lyricUri                  | string                    | No        | Lyric URI of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4701e41f4b71Sopenharmony_ci| artist                    | string                    | No        | Author of the lyric of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4702e41f4b71Sopenharmony_ci| fdSrc                     | media.AVFileDescriptor    | No        | Handle to the local media file in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4703e41f4b71Sopenharmony_ci| dataSrc<sup>12+</sup>     | media.AVDataSrcDescriptor | No        | Descriptor of the data source in the playlist.               |
4704e41f4b71Sopenharmony_ci| drmScheme<sup>12+</sup>   | string                    | No        | DRM scheme supported by the playlist. The value is the UUID of the DRM scheme. |
4705e41f4b71Sopenharmony_ci| duration                  | number                    | No        | Playback duration of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4706e41f4b71Sopenharmony_ci| startPosition             | number                    | No        | Start position for playing the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4707e41f4b71Sopenharmony_ci| creditsPosition           | number                    | No        | Position for playing the closing credits of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4708e41f4b71Sopenharmony_ci| appName                   | string                    | No        | Name of the application provided by the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4709e41f4b71Sopenharmony_ci| displayTags<sup>11+</sup> | number                    | No        | Display tags of the media asset. For details, see [DisplayTag](#displaytag11).<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4710e41f4b71Sopenharmony_ci
4711e41f4b71Sopenharmony_ci## AVQueueItem<sup>10+</sup>
4712e41f4b71Sopenharmony_ci
4713e41f4b71Sopenharmony_ciDescribes the attributes of an item in the playlist.
4714e41f4b71Sopenharmony_ci
4715e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4716e41f4b71Sopenharmony_ci
4717e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4718e41f4b71Sopenharmony_ci
4719e41f4b71Sopenharmony_ci| Name        | Type                                        | Mandatory | Description                                 |
4720e41f4b71Sopenharmony_ci| ----------- | ------------------------------------------- | --------- | ------------------------------------------- |
4721e41f4b71Sopenharmony_ci| itemId      | number                                      | Yes       | ID of an item in the playlist.              |
4722e41f4b71Sopenharmony_ci| description | [AVMediaDescription](#avmediadescription10) | No        | Media metadata of the item in the playlist. |
4723e41f4b71Sopenharmony_ci
4724e41f4b71Sopenharmony_ci## AVPlaybackState<sup>10+</sup>
4725e41f4b71Sopenharmony_ci
4726e41f4b71Sopenharmony_ciDescribes the information related to the media playback state.
4727e41f4b71Sopenharmony_ci
4728e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4729e41f4b71Sopenharmony_ci
4730e41f4b71Sopenharmony_ci| Name                       | Type                                    | Mandatory | Description                                                  |
4731e41f4b71Sopenharmony_ci| -------------------------- | --------------------------------------- | --------- | ------------------------------------------------------------ |
4732e41f4b71Sopenharmony_ci| state                      | [PlaybackState](#playbackstate10)       | No        | Playback state.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4733e41f4b71Sopenharmony_ci| speed                      | number                                  | No        | Playback speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4734e41f4b71Sopenharmony_ci| position                   | [PlaybackPosition](#playbackposition10) | No        | Playback position.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4735e41f4b71Sopenharmony_ci| bufferedTime               | number                                  | No        | Buffered time.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4736e41f4b71Sopenharmony_ci| loopMode                   | [LoopMode](#loopmode10)                 | No        | Loop mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4737e41f4b71Sopenharmony_ci| isFavorite                 | boolean                                 | No        | Whether the media asset is favorited.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4738e41f4b71Sopenharmony_ci| activeItemId<sup>10+</sup> | number                                  | No        | ID of the item that is being played.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4739e41f4b71Sopenharmony_ci| volume<sup>10+</sup>       | number                                  | No        | Media volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4740e41f4b71Sopenharmony_ci| maxVolume<sup>11+</sup>    | number                                  | No        | Maximum volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4741e41f4b71Sopenharmony_ci| muted<sup>11+</sup>        | boolean                                 | No        | Mute status. The value **true** means the muted state.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4742e41f4b71Sopenharmony_ci| duration<sup>11+</sup>     | number                                  | No        | Duration of the media asset.                                 |
4743e41f4b71Sopenharmony_ci| videoWidth<sup>11+</sup>   | number                                  | No        | Video width of the media asset, in px.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4744e41f4b71Sopenharmony_ci| videoHeight<sup>11+</sup>  | number                                  | No        | Video height of the media asset, in px.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4745e41f4b71Sopenharmony_ci| extras<sup>10+</sup>       | {[key: string]: Object}                 | No        | Custom media data.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
4746e41f4b71Sopenharmony_ci
4747e41f4b71Sopenharmony_ci## PlaybackPosition<sup>10+</sup>
4748e41f4b71Sopenharmony_ci
4749e41f4b71Sopenharmony_ciDescribes the information related to the playback position.
4750e41f4b71Sopenharmony_ci
4751e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4752e41f4b71Sopenharmony_ci
4753e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4754e41f4b71Sopenharmony_ci
4755e41f4b71Sopenharmony_ci| Name        | Type   | Mandatory | Description          |
4756e41f4b71Sopenharmony_ci| ----------- | ------ | --------- | -------------------- |
4757e41f4b71Sopenharmony_ci| elapsedTime | number | Yes       | Elapsed time, in ms. |
4758e41f4b71Sopenharmony_ci| updateTime  | number | Yes       | Updated time, in ms. |
4759e41f4b71Sopenharmony_ci
4760e41f4b71Sopenharmony_ci## CallMetadata<sup>11+</sup>
4761e41f4b71Sopenharmony_ci
4762e41f4b71Sopenharmony_ciDefines the attributes related to call metadata.
4763e41f4b71Sopenharmony_ci
4764e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4765e41f4b71Sopenharmony_ci
4766e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4767e41f4b71Sopenharmony_ci
4768e41f4b71Sopenharmony_ci| Name        | Type                                                         | Mandatory | Description                    |
4769e41f4b71Sopenharmony_ci| ----------- | ------------------------------------------------------------ | --------- | ------------------------------ |
4770e41f4b71Sopenharmony_ci| name        | string                                                       | No        | Name (alias) of the caller.    |
4771e41f4b71Sopenharmony_ci| phoneNumber | string                                                       | No        | Phone number of the caller.    |
4772e41f4b71Sopenharmony_ci| avatar      | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | No        | Profile picture of the caller. |
4773e41f4b71Sopenharmony_ci
4774e41f4b71Sopenharmony_ci## AVCallState<sup>11+</sup>
4775e41f4b71Sopenharmony_ci
4776e41f4b71Sopenharmony_ciDefines the attributes related to the call state.
4777e41f4b71Sopenharmony_ci
4778e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4779e41f4b71Sopenharmony_ci
4780e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4781e41f4b71Sopenharmony_ci
4782e41f4b71Sopenharmony_ci| Name  | Type                      | Mandatory | Description                                                  |
4783e41f4b71Sopenharmony_ci| ----- | ------------------------- | --------- | ------------------------------------------------------------ |
4784e41f4b71Sopenharmony_ci| state | [CallState](#callstate11) | Yes       | Call state.                                                  |
4785e41f4b71Sopenharmony_ci| muted | boolean                   | Yes       | Whether the microphone is muted.<br>**true**: The microphone is muted.<br>**false**: The microphone is not muted. |
4786e41f4b71Sopenharmony_ci
4787e41f4b71Sopenharmony_ci## CallState<sup>11+</sup>
4788e41f4b71Sopenharmony_ci
4789e41f4b71Sopenharmony_ciEnumerates the call states.
4790e41f4b71Sopenharmony_ci
4791e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4792e41f4b71Sopenharmony_ci
4793e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4794e41f4b71Sopenharmony_ci
4795e41f4b71Sopenharmony_ci| Name                     | Value | Description                         |
4796e41f4b71Sopenharmony_ci| ------------------------ | ----- | ----------------------------------- |
4797e41f4b71Sopenharmony_ci| CALL_STATE_IDLE          | 0     | The phone is idle.                  |
4798e41f4b71Sopenharmony_ci| CALL_STATE_INCOMING      | 1     | The phone is ringing.               |
4799e41f4b71Sopenharmony_ci| CALL_STATE_ACTIVE        | 2     | The call is connected.              |
4800e41f4b71Sopenharmony_ci| CALL_STATE_DIALING       | 3     | The caller is dialing.              |
4801e41f4b71Sopenharmony_ci| CALL_STATE_WAITING       | 4     | The call is waiting for connection. |
4802e41f4b71Sopenharmony_ci| CALL_STATE_HOLDING       | 5     | The call is placed on hold.         |
4803e41f4b71Sopenharmony_ci| CALL_STATE_DISCONNECTING | 6     | The call is disconnecting.          |
4804e41f4b71Sopenharmony_ci
4805e41f4b71Sopenharmony_ci## DisplayTag<sup>11+</sup>
4806e41f4b71Sopenharmony_ci
4807e41f4b71Sopenharmony_ciEnumerates the display tags of the media asset, which is a special type identifier of the media audio source.
4808e41f4b71Sopenharmony_ci
4809e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4810e41f4b71Sopenharmony_ci
4811e41f4b71Sopenharmony_ci| Name            | Value | Description |
4812e41f4b71Sopenharmony_ci| --------------- | ----- | ----------- |
4813e41f4b71Sopenharmony_ci| TAG_AUDIO_VIVID | 1     | AUDIO VIVID |
4814e41f4b71Sopenharmony_ci
4815e41f4b71Sopenharmony_ci## AVCastCategory<sup>10+</sup>
4816e41f4b71Sopenharmony_ci
4817e41f4b71Sopenharmony_ciEnumerates the cast categories.
4818e41f4b71Sopenharmony_ci
4819e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4820e41f4b71Sopenharmony_ci
4821e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4822e41f4b71Sopenharmony_ci
4823e41f4b71Sopenharmony_ci| Name            | Value | Description                                                  |
4824e41f4b71Sopenharmony_ci| --------------- | ----- | ------------------------------------------------------------ |
4825e41f4b71Sopenharmony_ci| CATEGORY_LOCAL  | 0     | Local playback. The sound is played from the local device or a connected Bluetooth headset by default. |
4826e41f4b71Sopenharmony_ci| CATEGORY_REMOTE | 1     | Remote playback. The sound or images are played from a remote device. |
4827e41f4b71Sopenharmony_ci
4828e41f4b71Sopenharmony_ci## DeviceType<sup>10+</sup>
4829e41f4b71Sopenharmony_ci
4830e41f4b71Sopenharmony_ciEnumerates the output device types.
4831e41f4b71Sopenharmony_ci
4832e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4833e41f4b71Sopenharmony_ci
4834e41f4b71Sopenharmony_ci| Name                      | Value | Description                                                  |
4835e41f4b71Sopenharmony_ci| ------------------------- | ----- | ------------------------------------------------------------ |
4836e41f4b71Sopenharmony_ci| DEVICE_TYPE_LOCAL         | 0     | Local device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core |
4837e41f4b71Sopenharmony_ci| DEVICE_TYPE_BLUETOOTH     | 10    | Bluetooth device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core |
4838e41f4b71Sopenharmony_ci| DEVICE_TYPE_TV            | 2     | TV.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast |
4839e41f4b71Sopenharmony_ci| DEVICE_TYPE_SMART_SPEAKER | 3     | Speaker.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast |
4840e41f4b71Sopenharmony_ci
4841e41f4b71Sopenharmony_ci## DeviceInfo<sup>10+</sup>
4842e41f4b71Sopenharmony_ci
4843e41f4b71Sopenharmony_ciDescribes the information related to the output device.
4844e41f4b71Sopenharmony_ci
4845e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4846e41f4b71Sopenharmony_ci
4847e41f4b71Sopenharmony_ci| Name                                   | Type           | Mandatory | Description                                                  |
4848e41f4b71Sopenharmony_ci| -------------------------------------- | -------------- | --------- | ------------------------------------------------------------ |
4849e41f4b71Sopenharmony_ci| castCategory                           | AVCastCategory | Yes       | Cast category.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core |
4850e41f4b71Sopenharmony_ci| deviceId                               | string         | Yes       | ID of the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core |
4851e41f4b71Sopenharmony_ci| deviceName                             | string         | Yes       | Name of the output device.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core |
4852e41f4b71Sopenharmony_ci| deviceType                             | DeviceType     | Yes       | Type of the output device.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core |
4853e41f4b71Sopenharmony_ci| supportedProtocols<sup>11+</sup>       | number         | No        | Protocol supported by the output device. The default value is **TYPE_LOCAL**. For details, see [ProtocolType](#protocoltype11).<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast |
4854e41f4b71Sopenharmony_ci| supportedDrmCapabilities<sup>12+</sup> | Array\<string> | No        | DRM capability supported by the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast |
4855e41f4b71Sopenharmony_ci
4856e41f4b71Sopenharmony_ci## OutputDeviceInfo<sup>10+</sup>
4857e41f4b71Sopenharmony_ci
4858e41f4b71Sopenharmony_ciDescribes the information related to the output device.
4859e41f4b71Sopenharmony_ci
4860e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4861e41f4b71Sopenharmony_ci
4862e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4863e41f4b71Sopenharmony_ci
4864e41f4b71Sopenharmony_ci| Name    | Type                | Mandatory | Description     |
4865e41f4b71Sopenharmony_ci| ------- | ------------------- | --------- | --------------- |
4866e41f4b71Sopenharmony_ci| devices | Array\<DeviceInfo\> | Yes       | Output devices. |
4867e41f4b71Sopenharmony_ci
4868e41f4b71Sopenharmony_ci## LoopMode<sup>10+</sup>
4869e41f4b71Sopenharmony_ci
4870e41f4b71Sopenharmony_ciEnumerates the loop modes of media playback.
4871e41f4b71Sopenharmony_ci
4872e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4873e41f4b71Sopenharmony_ci
4874e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4875e41f4b71Sopenharmony_ci
4876e41f4b71Sopenharmony_ci| Name                           | Value | Description          |
4877e41f4b71Sopenharmony_ci| ------------------------------ | ----- | -------------------- |
4878e41f4b71Sopenharmony_ci| LOOP_MODE_SEQUENCE             | 0     | Sequential playback. |
4879e41f4b71Sopenharmony_ci| LOOP_MODE_SINGLE               | 1     | Single loop.         |
4880e41f4b71Sopenharmony_ci| LOOP_MODE_LIST                 | 2     | Playlist loop.       |
4881e41f4b71Sopenharmony_ci| LOOP_MODE_SHUFFLE              | 3     | Shuffle.             |
4882e41f4b71Sopenharmony_ci| LOOP_MODE_CUSTOM<sup>11+</sup> | 4     | Custom playback.     |
4883e41f4b71Sopenharmony_ci
4884e41f4b71Sopenharmony_ci## PlaybackState<sup>10+</sup>
4885e41f4b71Sopenharmony_ci
4886e41f4b71Sopenharmony_ciEnumerates the media playback states.
4887e41f4b71Sopenharmony_ci
4888e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4889e41f4b71Sopenharmony_ci
4890e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4891e41f4b71Sopenharmony_ci
4892e41f4b71Sopenharmony_ci| Name                                   | Value | Description        |
4893e41f4b71Sopenharmony_ci| -------------------------------------- | ----- | ------------------ |
4894e41f4b71Sopenharmony_ci| PLAYBACK_STATE_INITIAL                 | 0     | Initial.           |
4895e41f4b71Sopenharmony_ci| PLAYBACK_STATE_PREPARE                 | 1     | Preparing.         |
4896e41f4b71Sopenharmony_ci| PLAYBACK_STATE_PLAY                    | 2     | Playing.           |
4897e41f4b71Sopenharmony_ci| PLAYBACK_STATE_PAUSE                   | 3     | Paused.            |
4898e41f4b71Sopenharmony_ci| PLAYBACK_STATE_FAST_FORWARD            | 4     | Fast-forward.      |
4899e41f4b71Sopenharmony_ci| PLAYBACK_STATE_REWIND                  | 5     | Rewind.            |
4900e41f4b71Sopenharmony_ci| PLAYBACK_STATE_STOP                    | 6     | Stop the playback. |
4901e41f4b71Sopenharmony_ci| PLAYBACK_STATE_COMPLETED               | 7     | Playback complete. |
4902e41f4b71Sopenharmony_ci| PLAYBACK_STATE_RELEASED                | 8     | Released.          |
4903e41f4b71Sopenharmony_ci| PLAYBACK_STATE_ERROR                   | 9     | Error.             |
4904e41f4b71Sopenharmony_ci| PLAYBACK_STATE_IDLE<sup>11+</sup>      | 10    | Idle.              |
4905e41f4b71Sopenharmony_ci| PLAYBACK_STATE_BUFFERING<sup>11+</sup> | 11    | Buffering.         |
4906e41f4b71Sopenharmony_ci
4907e41f4b71Sopenharmony_ci## AVSessionController<sup>10+</sup>
4908e41f4b71Sopenharmony_ci
4909e41f4b71Sopenharmony_ciThrough the AV session controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
4910e41f4b71Sopenharmony_ci
4911e41f4b71Sopenharmony_ci### Attributes
4912e41f4b71Sopenharmony_ci
4913e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4914e41f4b71Sopenharmony_ci
4915e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4916e41f4b71Sopenharmony_ci
4917e41f4b71Sopenharmony_ci| Name      | Type   | Readable | Writable | Description                                              |
4918e41f4b71Sopenharmony_ci| :-------- | :----- | :------- | :------- | :------------------------------------------------------- |
4919e41f4b71Sopenharmony_ci| sessionId | string | Yes      | No       | Unique session ID of the **AVSessionController** object. |
4920e41f4b71Sopenharmony_ci
4921e41f4b71Sopenharmony_ci
4922e41f4b71Sopenharmony_ci**Example**
4923e41f4b71Sopenharmony_ci
4924e41f4b71Sopenharmony_ci```ts
4925e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4926e41f4b71Sopenharmony_ci
4927e41f4b71Sopenharmony_cilet AVSessionController: avSession.AVSessionController;
4928e41f4b71Sopenharmony_ciavSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
4929e41f4b71Sopenharmony_ci  AVSessionController = controller;
4930e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
4931e41f4b71Sopenharmony_ci  console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
4932e41f4b71Sopenharmony_ci});
4933e41f4b71Sopenharmony_ci```
4934e41f4b71Sopenharmony_ci
4935e41f4b71Sopenharmony_ci### getAVPlaybackState<sup>10+</sup>
4936e41f4b71Sopenharmony_ci
4937e41f4b71Sopenharmony_cigetAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
4938e41f4b71Sopenharmony_ci
4939e41f4b71Sopenharmony_ciObtains the remote playback state. This API uses an asynchronous callback to return the result.
4940e41f4b71Sopenharmony_ci
4941e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4942e41f4b71Sopenharmony_ci
4943e41f4b71Sopenharmony_ci**Parameters**
4944e41f4b71Sopenharmony_ci
4945e41f4b71Sopenharmony_ci| Name     | Type                                                  | Mandatory | Description                                        |
4946e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | --------- | -------------------------------------------------- |
4947e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes       | Callback used to return the remote playback state. |
4948e41f4b71Sopenharmony_ci
4949e41f4b71Sopenharmony_ci**Error codes**
4950e41f4b71Sopenharmony_ci
4951e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4952e41f4b71Sopenharmony_ci
4953e41f4b71Sopenharmony_ci| ID      | Error Message                          |
4954e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
4955e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
4956e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
4957e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
4958e41f4b71Sopenharmony_ci
4959e41f4b71Sopenharmony_ci**Example**
4960e41f4b71Sopenharmony_ci
4961e41f4b71Sopenharmony_ci```ts
4962e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4963e41f4b71Sopenharmony_ci
4964e41f4b71Sopenharmony_ciavsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
4965e41f4b71Sopenharmony_ci  if (err) {
4966e41f4b71Sopenharmony_ci    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
4967e41f4b71Sopenharmony_ci  } else {
4968e41f4b71Sopenharmony_ci    console.info('getAVPlaybackState : SUCCESS');
4969e41f4b71Sopenharmony_ci  }
4970e41f4b71Sopenharmony_ci});
4971e41f4b71Sopenharmony_ci```
4972e41f4b71Sopenharmony_ci
4973e41f4b71Sopenharmony_ci### getAVPlaybackState<sup>10+</sup>
4974e41f4b71Sopenharmony_ci
4975e41f4b71Sopenharmony_cigetAVPlaybackState(): Promise\<AVPlaybackState>
4976e41f4b71Sopenharmony_ci
4977e41f4b71Sopenharmony_ciObtains the remote playback state. This API uses a promise to return the result.
4978e41f4b71Sopenharmony_ci
4979e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4980e41f4b71Sopenharmony_ci
4981e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
4982e41f4b71Sopenharmony_ci
4983e41f4b71Sopenharmony_ci**Return value**
4984e41f4b71Sopenharmony_ci
4985e41f4b71Sopenharmony_ci| Type                                            | Description                                       |
4986e41f4b71Sopenharmony_ci| ----------------------------------------------- | ------------------------------------------------- |
4987e41f4b71Sopenharmony_ci| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state. |
4988e41f4b71Sopenharmony_ci
4989e41f4b71Sopenharmony_ci**Error codes**
4990e41f4b71Sopenharmony_ci
4991e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4992e41f4b71Sopenharmony_ci
4993e41f4b71Sopenharmony_ci| ID      | Error Message                          |
4994e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
4995e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
4996e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
4997e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
4998e41f4b71Sopenharmony_ci
4999e41f4b71Sopenharmony_ci**Example**
5000e41f4b71Sopenharmony_ci
5001e41f4b71Sopenharmony_ci```ts
5002e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5003e41f4b71Sopenharmony_ci
5004e41f4b71Sopenharmony_ciavsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
5005e41f4b71Sopenharmony_ci  console.info('getAVPlaybackState : SUCCESS');
5006e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5007e41f4b71Sopenharmony_ci  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5008e41f4b71Sopenharmony_ci});
5009e41f4b71Sopenharmony_ci```
5010e41f4b71Sopenharmony_ci
5011e41f4b71Sopenharmony_ci### getAVMetadata<sup>10+</sup>
5012e41f4b71Sopenharmony_ci
5013e41f4b71Sopenharmony_cigetAVMetadata(): Promise\<AVMetadata>
5014e41f4b71Sopenharmony_ci
5015e41f4b71Sopenharmony_ciObtains the session metadata. This API uses a promise to return the result.
5016e41f4b71Sopenharmony_ci
5017e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5018e41f4b71Sopenharmony_ci
5019e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5020e41f4b71Sopenharmony_ci
5021e41f4b71Sopenharmony_ci**Return value**
5022e41f4b71Sopenharmony_ci
5023e41f4b71Sopenharmony_ci| Type                                  | Description                                   |
5024e41f4b71Sopenharmony_ci| ------------------------------------- | --------------------------------------------- |
5025e41f4b71Sopenharmony_ci| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained. |
5026e41f4b71Sopenharmony_ci
5027e41f4b71Sopenharmony_ci**Error codes**
5028e41f4b71Sopenharmony_ci
5029e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5030e41f4b71Sopenharmony_ci
5031e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5032e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5033e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5034e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5035e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5036e41f4b71Sopenharmony_ci
5037e41f4b71Sopenharmony_ci**Example**
5038e41f4b71Sopenharmony_ci
5039e41f4b71Sopenharmony_ci```ts
5040e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5041e41f4b71Sopenharmony_ci
5042e41f4b71Sopenharmony_ciavsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => {
5043e41f4b71Sopenharmony_ci  console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5044e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5045e41f4b71Sopenharmony_ci  console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5046e41f4b71Sopenharmony_ci});
5047e41f4b71Sopenharmony_ci```
5048e41f4b71Sopenharmony_ci
5049e41f4b71Sopenharmony_ci### getAVMetadata<sup>10+</sup>
5050e41f4b71Sopenharmony_ci
5051e41f4b71Sopenharmony_cigetAVMetadata(callback: AsyncCallback\<AVMetadata>): void
5052e41f4b71Sopenharmony_ci
5053e41f4b71Sopenharmony_ciObtains the session metadata. This API uses an asynchronous callback to return the result.
5054e41f4b71Sopenharmony_ci
5055e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5056e41f4b71Sopenharmony_ci
5057e41f4b71Sopenharmony_ci**Parameters**
5058e41f4b71Sopenharmony_ci
5059e41f4b71Sopenharmony_ci| Name     | Type                                        | Mandatory | Description                                    |
5060e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | --------- | ---------------------------------------------- |
5061e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes       | Callback used to return the metadata obtained. |
5062e41f4b71Sopenharmony_ci
5063e41f4b71Sopenharmony_ci**Error codes**
5064e41f4b71Sopenharmony_ci
5065e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5066e41f4b71Sopenharmony_ci
5067e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5068e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5069e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5070e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5071e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5072e41f4b71Sopenharmony_ci
5073e41f4b71Sopenharmony_ci**Example**
5074e41f4b71Sopenharmony_ci
5075e41f4b71Sopenharmony_ci```ts
5076e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5077e41f4b71Sopenharmony_ci
5078e41f4b71Sopenharmony_ciavsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
5079e41f4b71Sopenharmony_ci  if (err) {
5080e41f4b71Sopenharmony_ci    console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5081e41f4b71Sopenharmony_ci  } else {
5082e41f4b71Sopenharmony_ci    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5083e41f4b71Sopenharmony_ci  }
5084e41f4b71Sopenharmony_ci});
5085e41f4b71Sopenharmony_ci```
5086e41f4b71Sopenharmony_ci
5087e41f4b71Sopenharmony_ci### getAVQueueTitle<sup>10+</sup>
5088e41f4b71Sopenharmony_ci
5089e41f4b71Sopenharmony_cigetAVQueueTitle(): Promise\<string>
5090e41f4b71Sopenharmony_ci
5091e41f4b71Sopenharmony_ciObtains the name of the playlist. This API uses a promise to return the result.
5092e41f4b71Sopenharmony_ci
5093e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5094e41f4b71Sopenharmony_ci
5095e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5096e41f4b71Sopenharmony_ci
5097e41f4b71Sopenharmony_ci**Return value**
5098e41f4b71Sopenharmony_ci
5099e41f4b71Sopenharmony_ci| Type             | Description                               |
5100e41f4b71Sopenharmony_ci| ---------------- | ----------------------------------------- |
5101e41f4b71Sopenharmony_ci| Promise<string\> | Promise used to return the playlist name. |
5102e41f4b71Sopenharmony_ci
5103e41f4b71Sopenharmony_ci**Error codes**
5104e41f4b71Sopenharmony_ci
5105e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5106e41f4b71Sopenharmony_ci
5107e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5108e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5109e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5110e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5111e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5112e41f4b71Sopenharmony_ci
5113e41f4b71Sopenharmony_ci**Example**
5114e41f4b71Sopenharmony_ci
5115e41f4b71Sopenharmony_ci```ts
5116e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5117e41f4b71Sopenharmony_ci
5118e41f4b71Sopenharmony_ciavsessionController.getAVQueueTitle().then((title: string) => {
5119e41f4b71Sopenharmony_ci  console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5120e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5121e41f4b71Sopenharmony_ci  console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5122e41f4b71Sopenharmony_ci});
5123e41f4b71Sopenharmony_ci```
5124e41f4b71Sopenharmony_ci
5125e41f4b71Sopenharmony_ci### getAVQueueTitle<sup>10+</sup>
5126e41f4b71Sopenharmony_ci
5127e41f4b71Sopenharmony_cigetAVQueueTitle(callback: AsyncCallback\<string>): void
5128e41f4b71Sopenharmony_ci
5129e41f4b71Sopenharmony_ciObtains the name of the playlist. This API uses an asynchronous callback to return the result.
5130e41f4b71Sopenharmony_ci
5131e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5132e41f4b71Sopenharmony_ci
5133e41f4b71Sopenharmony_ci**Parameters**
5134e41f4b71Sopenharmony_ci
5135e41f4b71Sopenharmony_ci| Name     | Type                   | Mandatory | Description                                |
5136e41f4b71Sopenharmony_ci| -------- | ---------------------- | --------- | ------------------------------------------ |
5137e41f4b71Sopenharmony_ci| callback | AsyncCallback<string\> | Yes       | Callback used to return the playlist name. |
5138e41f4b71Sopenharmony_ci
5139e41f4b71Sopenharmony_ci**Error codes**
5140e41f4b71Sopenharmony_ci
5141e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5142e41f4b71Sopenharmony_ci
5143e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5144e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5145e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5146e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5147e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5148e41f4b71Sopenharmony_ci
5149e41f4b71Sopenharmony_ci**Example**
5150e41f4b71Sopenharmony_ci
5151e41f4b71Sopenharmony_ci```ts
5152e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5153e41f4b71Sopenharmony_ci
5154e41f4b71Sopenharmony_ciavsessionController.getAVQueueTitle((err: BusinessError, title: string) => {
5155e41f4b71Sopenharmony_ci  if (err) {
5156e41f4b71Sopenharmony_ci    console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5157e41f4b71Sopenharmony_ci  } else {
5158e41f4b71Sopenharmony_ci    console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5159e41f4b71Sopenharmony_ci  }
5160e41f4b71Sopenharmony_ci});
5161e41f4b71Sopenharmony_ci```
5162e41f4b71Sopenharmony_ci
5163e41f4b71Sopenharmony_ci### getAVQueueItems<sup>10+</sup>
5164e41f4b71Sopenharmony_ci
5165e41f4b71Sopenharmony_cigetAVQueueItems(): Promise\<Array\<AVQueueItem>>
5166e41f4b71Sopenharmony_ci
5167e41f4b71Sopenharmony_ciObtains the information related to the items in the queue. This API uses a promise to return the result.
5168e41f4b71Sopenharmony_ci
5169e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5170e41f4b71Sopenharmony_ci
5171e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5172e41f4b71Sopenharmony_ci
5173e41f4b71Sopenharmony_ci**Return value**
5174e41f4b71Sopenharmony_ci
5175e41f4b71Sopenharmony_ci| Type                                            | Description                                    |
5176e41f4b71Sopenharmony_ci| ----------------------------------------------- | ---------------------------------------------- |
5177e41f4b71Sopenharmony_ci| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise used to return the items in the queue. |
5178e41f4b71Sopenharmony_ci
5179e41f4b71Sopenharmony_ci**Error codes**
5180e41f4b71Sopenharmony_ci
5181e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5182e41f4b71Sopenharmony_ci
5183e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5184e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5185e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5186e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5187e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5188e41f4b71Sopenharmony_ci
5189e41f4b71Sopenharmony_ci**Example**
5190e41f4b71Sopenharmony_ci
5191e41f4b71Sopenharmony_ci```ts
5192e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5193e41f4b71Sopenharmony_ci
5194e41f4b71Sopenharmony_ciavsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
5195e41f4b71Sopenharmony_ci  console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5196e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5197e41f4b71Sopenharmony_ci  console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5198e41f4b71Sopenharmony_ci});
5199e41f4b71Sopenharmony_ci```
5200e41f4b71Sopenharmony_ci
5201e41f4b71Sopenharmony_ci### getAVQueueItems<sup>10+</sup>
5202e41f4b71Sopenharmony_ci
5203e41f4b71Sopenharmony_cigetAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void
5204e41f4b71Sopenharmony_ci
5205e41f4b71Sopenharmony_ciObtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result.
5206e41f4b71Sopenharmony_ci
5207e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5208e41f4b71Sopenharmony_ci
5209e41f4b71Sopenharmony_ci**Parameters**
5210e41f4b71Sopenharmony_ci
5211e41f4b71Sopenharmony_ci| Name     | Type                                                  | Mandatory | Description                                        |
5212e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | --------- | -------------------------------------------------- |
5213e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | Yes       | Callback used to return the items in the playlist. |
5214e41f4b71Sopenharmony_ci
5215e41f4b71Sopenharmony_ci**Error codes**
5216e41f4b71Sopenharmony_ci
5217e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5218e41f4b71Sopenharmony_ci
5219e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5220e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5221e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5222e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5223e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5224e41f4b71Sopenharmony_ci
5225e41f4b71Sopenharmony_ci**Example**
5226e41f4b71Sopenharmony_ci
5227e41f4b71Sopenharmony_ci```ts
5228e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5229e41f4b71Sopenharmony_ci
5230e41f4b71Sopenharmony_ciavsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
5231e41f4b71Sopenharmony_ci  if (err) {
5232e41f4b71Sopenharmony_ci    console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5233e41f4b71Sopenharmony_ci  } else {
5234e41f4b71Sopenharmony_ci    console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5235e41f4b71Sopenharmony_ci  }
5236e41f4b71Sopenharmony_ci});
5237e41f4b71Sopenharmony_ci```
5238e41f4b71Sopenharmony_ci
5239e41f4b71Sopenharmony_ci### skipToQueueItem<sup>10+</sup>
5240e41f4b71Sopenharmony_ci
5241e41f4b71Sopenharmony_ciskipToQueueItem(itemId: number): Promise\<void>
5242e41f4b71Sopenharmony_ci
5243e41f4b71Sopenharmony_ciSends 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.
5244e41f4b71Sopenharmony_ci
5245e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5246e41f4b71Sopenharmony_ci
5247e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5248e41f4b71Sopenharmony_ci
5249e41f4b71Sopenharmony_ci**Parameters**
5250e41f4b71Sopenharmony_ci
5251e41f4b71Sopenharmony_ci| Name   | Type   | Mandatory | Description                    |
5252e41f4b71Sopenharmony_ci| ------ | ------ | --------- | ------------------------------ |
5253e41f4b71Sopenharmony_ci| itemId | number | Yes       | ID of an item in the playlist. |
5254e41f4b71Sopenharmony_ci
5255e41f4b71Sopenharmony_ci**Return value**
5256e41f4b71Sopenharmony_ci
5257e41f4b71Sopenharmony_ci| Type           | Description                                                  |
5258e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
5259e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned. |
5260e41f4b71Sopenharmony_ci
5261e41f4b71Sopenharmony_ci**Error codes**
5262e41f4b71Sopenharmony_ci
5263e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5264e41f4b71Sopenharmony_ci
5265e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
5266e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
5267e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5268e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
5269e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
5270e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
5271e41f4b71Sopenharmony_ci
5272e41f4b71Sopenharmony_ci**Example**
5273e41f4b71Sopenharmony_ci
5274e41f4b71Sopenharmony_ci```ts
5275e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5276e41f4b71Sopenharmony_ci
5277e41f4b71Sopenharmony_cilet queueItemId = 0;
5278e41f4b71Sopenharmony_ciavsessionController.skipToQueueItem(queueItemId).then(() => {
5279e41f4b71Sopenharmony_ci  console.info('SkipToQueueItem successfully');
5280e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5281e41f4b71Sopenharmony_ci  console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5282e41f4b71Sopenharmony_ci});
5283e41f4b71Sopenharmony_ci```
5284e41f4b71Sopenharmony_ci
5285e41f4b71Sopenharmony_ci### skipToQueueItem<sup>10+</sup>
5286e41f4b71Sopenharmony_ci
5287e41f4b71Sopenharmony_ciskipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void
5288e41f4b71Sopenharmony_ci
5289e41f4b71Sopenharmony_ciSends 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.
5290e41f4b71Sopenharmony_ci
5291e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5292e41f4b71Sopenharmony_ci
5293e41f4b71Sopenharmony_ci**Parameters**
5294e41f4b71Sopenharmony_ci
5295e41f4b71Sopenharmony_ci| Name     | Type                 | Mandatory | Description                                                  |
5296e41f4b71Sopenharmony_ci| -------- | -------------------- | --------- | ------------------------------------------------------------ |
5297e41f4b71Sopenharmony_ci| itemId   | number               | Yes       | ID of an item in the playlist.                               |
5298e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. |
5299e41f4b71Sopenharmony_ci
5300e41f4b71Sopenharmony_ci**Error codes**
5301e41f4b71Sopenharmony_ci
5302e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5303e41f4b71Sopenharmony_ci
5304e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
5305e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
5306e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5307e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
5308e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
5309e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
5310e41f4b71Sopenharmony_ci
5311e41f4b71Sopenharmony_ci**Example**
5312e41f4b71Sopenharmony_ci
5313e41f4b71Sopenharmony_ci```ts
5314e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5315e41f4b71Sopenharmony_ci
5316e41f4b71Sopenharmony_cilet queueItemId = 0;
5317e41f4b71Sopenharmony_ciavsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => {
5318e41f4b71Sopenharmony_ci  if (err) {
5319e41f4b71Sopenharmony_ci    console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5320e41f4b71Sopenharmony_ci  } else {
5321e41f4b71Sopenharmony_ci    console.info('SkipToQueueItem successfully');
5322e41f4b71Sopenharmony_ci  }
5323e41f4b71Sopenharmony_ci});
5324e41f4b71Sopenharmony_ci```
5325e41f4b71Sopenharmony_ci
5326e41f4b71Sopenharmony_ci### getOutputDevice<sup>10+</sup>
5327e41f4b71Sopenharmony_ci
5328e41f4b71Sopenharmony_cigetOutputDevice(): Promise\<OutputDeviceInfo>
5329e41f4b71Sopenharmony_ci
5330e41f4b71Sopenharmony_ciObtains the output device information. This API uses a promise to return the result.
5331e41f4b71Sopenharmony_ci
5332e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5333e41f4b71Sopenharmony_ci
5334e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5335e41f4b71Sopenharmony_ci
5336e41f4b71Sopenharmony_ci**Return value**
5337e41f4b71Sopenharmony_ci
5338e41f4b71Sopenharmony_ci| Type                                              | Description                                      |
5339e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------------------------------------ |
5340e41f4b71Sopenharmony_ci| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained. |
5341e41f4b71Sopenharmony_ci
5342e41f4b71Sopenharmony_ci**Error codes**
5343e41f4b71Sopenharmony_ci
5344e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5345e41f4b71Sopenharmony_ci
5346e41f4b71Sopenharmony_ci| ID     | Error Message                          |
5347e41f4b71Sopenharmony_ci| ------ | -------------------------------------- |
5348e41f4b71Sopenharmony_ci| 600101 | Session service exception.             |
5349e41f4b71Sopenharmony_ci| 600103 | The session controller does not exist. |
5350e41f4b71Sopenharmony_ci
5351e41f4b71Sopenharmony_ci**Example**
5352e41f4b71Sopenharmony_ci
5353e41f4b71Sopenharmony_ci```ts
5354e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5355e41f4b71Sopenharmony_ci
5356e41f4b71Sopenharmony_ciavsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
5357e41f4b71Sopenharmony_ci  console.info('GetOutputDevice : SUCCESS');
5358e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5359e41f4b71Sopenharmony_ci  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5360e41f4b71Sopenharmony_ci});
5361e41f4b71Sopenharmony_ci```
5362e41f4b71Sopenharmony_ci
5363e41f4b71Sopenharmony_ci### getOutputDevice<sup>10+</sup>
5364e41f4b71Sopenharmony_ci
5365e41f4b71Sopenharmony_cigetOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
5366e41f4b71Sopenharmony_ci
5367e41f4b71Sopenharmony_ciObtains the output device information. This API uses an asynchronous callback to return the result.
5368e41f4b71Sopenharmony_ci
5369e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5370e41f4b71Sopenharmony_ci
5371e41f4b71Sopenharmony_ci**Parameters**
5372e41f4b71Sopenharmony_ci
5373e41f4b71Sopenharmony_ci| Name     | Type                                                    | Mandatory | Description                                       |
5374e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------- |
5375e41f4b71Sopenharmony_ci| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes       | Callback used to return the information obtained. |
5376e41f4b71Sopenharmony_ci
5377e41f4b71Sopenharmony_ci**Error codes**
5378e41f4b71Sopenharmony_ci
5379e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5380e41f4b71Sopenharmony_ci
5381e41f4b71Sopenharmony_ci| ID     | Error Message                          |
5382e41f4b71Sopenharmony_ci| ------ | -------------------------------------- |
5383e41f4b71Sopenharmony_ci| 600101 | Session service exception.             |
5384e41f4b71Sopenharmony_ci| 600103 | The session controller does not exist. |
5385e41f4b71Sopenharmony_ci
5386e41f4b71Sopenharmony_ci**Example**
5387e41f4b71Sopenharmony_ci
5388e41f4b71Sopenharmony_ci```ts
5389e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5390e41f4b71Sopenharmony_ci
5391e41f4b71Sopenharmony_ciavsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
5392e41f4b71Sopenharmony_ci  if (err) {
5393e41f4b71Sopenharmony_ci    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5394e41f4b71Sopenharmony_ci  } else {
5395e41f4b71Sopenharmony_ci    console.info('GetOutputDevice : SUCCESS');
5396e41f4b71Sopenharmony_ci  }
5397e41f4b71Sopenharmony_ci});
5398e41f4b71Sopenharmony_ci```
5399e41f4b71Sopenharmony_ci
5400e41f4b71Sopenharmony_ci### sendAVKeyEvent<sup>10+</sup>
5401e41f4b71Sopenharmony_ci
5402e41f4b71Sopenharmony_cisendAVKeyEvent(event: KeyEvent): Promise\<void>
5403e41f4b71Sopenharmony_ci
5404e41f4b71Sopenharmony_ciSends a key event to the session corresponding to this controller. This API uses a promise to return the result.
5405e41f4b71Sopenharmony_ci
5406e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5407e41f4b71Sopenharmony_ci
5408e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5409e41f4b71Sopenharmony_ci
5410e41f4b71Sopenharmony_ci**Parameters**
5411e41f4b71Sopenharmony_ci
5412e41f4b71Sopenharmony_ci| Name  | Type                                              | Mandatory | Description |
5413e41f4b71Sopenharmony_ci| ----- | ------------------------------------------------- | --------- | ----------- |
5414e41f4b71Sopenharmony_ci| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes       | Key event.  |
5415e41f4b71Sopenharmony_ci
5416e41f4b71Sopenharmony_ci**Error codes**
5417e41f4b71Sopenharmony_ci
5418e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5419e41f4b71Sopenharmony_ci
5420e41f4b71Sopenharmony_ci| ID     | Error Message                                                |
5421e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ |
5422e41f4b71Sopenharmony_ci| 401    | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5423e41f4b71Sopenharmony_ci| 600101 | Session service exception.                                   |
5424e41f4b71Sopenharmony_ci| 600102 | The session does not exist.                                  |
5425e41f4b71Sopenharmony_ci| 600103 | The session controller does not exist.                       |
5426e41f4b71Sopenharmony_ci| 600105 | Invalid session command.                                     |
5427e41f4b71Sopenharmony_ci| 600106 | The session is not activated.                                |
5428e41f4b71Sopenharmony_ci
5429e41f4b71Sopenharmony_ci**Return value**
5430e41f4b71Sopenharmony_ci
5431e41f4b71Sopenharmony_ci| Type           | Description                                                  |
5432e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
5433e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned. |
5434e41f4b71Sopenharmony_ci
5435e41f4b71Sopenharmony_ci**Example**
5436e41f4b71Sopenharmony_ci
5437e41f4b71Sopenharmony_ci```ts
5438e41f4b71Sopenharmony_ciimport { Key, KeyEvent } from '@kit.InputKit';
5439e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5440e41f4b71Sopenharmony_ci
5441e41f4b71Sopenharmony_cilet keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
5442e41f4b71Sopenharmony_cilet event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
5443e41f4b71Sopenharmony_ci
5444e41f4b71Sopenharmony_ci
5445e41f4b71Sopenharmony_ciavsessionController.sendAVKeyEvent(event).then(() => {
5446e41f4b71Sopenharmony_ci  console.info('SendAVKeyEvent Successfully');
5447e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5448e41f4b71Sopenharmony_ci  console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
5449e41f4b71Sopenharmony_ci});
5450e41f4b71Sopenharmony_ci```
5451e41f4b71Sopenharmony_ci
5452e41f4b71Sopenharmony_ci### sendAVKeyEvent<sup>10+</sup>
5453e41f4b71Sopenharmony_ci
5454e41f4b71Sopenharmony_cisendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
5455e41f4b71Sopenharmony_ci
5456e41f4b71Sopenharmony_ciSends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result.
5457e41f4b71Sopenharmony_ci
5458e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5459e41f4b71Sopenharmony_ci
5460e41f4b71Sopenharmony_ci**Parameters**
5461e41f4b71Sopenharmony_ci
5462e41f4b71Sopenharmony_ci| Name     | Type                                              | Mandatory | Description                                                  |
5463e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | --------- | ------------------------------------------------------------ |
5464e41f4b71Sopenharmony_ci| event    | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes       | Key event.                                                   |
5465e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                              | Yes       | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object. |
5466e41f4b71Sopenharmony_ci
5467e41f4b71Sopenharmony_ci**Error codes**
5468e41f4b71Sopenharmony_ci
5469e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5470e41f4b71Sopenharmony_ci
5471e41f4b71Sopenharmony_ci| ID     | Error Message                                                |
5472e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ |
5473e41f4b71Sopenharmony_ci| 401    | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5474e41f4b71Sopenharmony_ci| 600101 | Session service exception.                                   |
5475e41f4b71Sopenharmony_ci| 600102 | The session does not exist.                                  |
5476e41f4b71Sopenharmony_ci| 600103 | The session controller does not exist.                       |
5477e41f4b71Sopenharmony_ci| 600105 | Invalid session command.                                     |
5478e41f4b71Sopenharmony_ci| 600106 | The session is not activated.                                |
5479e41f4b71Sopenharmony_ci
5480e41f4b71Sopenharmony_ci**Example**
5481e41f4b71Sopenharmony_ci
5482e41f4b71Sopenharmony_ci```ts
5483e41f4b71Sopenharmony_ciimport { Key, KeyEvent } from '@kit.InputKit';
5484e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5485e41f4b71Sopenharmony_ci
5486e41f4b71Sopenharmony_cilet keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
5487e41f4b71Sopenharmony_cilet event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
5488e41f4b71Sopenharmony_ciavsessionController.sendAVKeyEvent(event, (err: BusinessError) => {
5489e41f4b71Sopenharmony_ci  if (err) {
5490e41f4b71Sopenharmony_ci    console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
5491e41f4b71Sopenharmony_ci  } else {
5492e41f4b71Sopenharmony_ci    console.info('SendAVKeyEvent Successfully');
5493e41f4b71Sopenharmony_ci  }
5494e41f4b71Sopenharmony_ci});
5495e41f4b71Sopenharmony_ci```
5496e41f4b71Sopenharmony_ci
5497e41f4b71Sopenharmony_ci### getLaunchAbility<sup>10+</sup>
5498e41f4b71Sopenharmony_ci
5499e41f4b71Sopenharmony_cigetLaunchAbility(): Promise\<WantAgent>
5500e41f4b71Sopenharmony_ci
5501e41f4b71Sopenharmony_ciObtains the **WantAgent** object saved by the application in the session. This API uses a promise to return the result.
5502e41f4b71Sopenharmony_ci
5503e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5504e41f4b71Sopenharmony_ci
5505e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5506e41f4b71Sopenharmony_ci
5507e41f4b71Sopenharmony_ci**Return value**
5508e41f4b71Sopenharmony_ci
5509e41f4b71Sopenharmony_ci| Type                                                         | Description                                                  |
5510e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ |
5511e41f4b71Sopenharmony_ci| Promise<[WantAgent](../apis-ability-kit/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. |
5512e41f4b71Sopenharmony_ci
5513e41f4b71Sopenharmony_ci**Error codes**
5514e41f4b71Sopenharmony_ci
5515e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5516e41f4b71Sopenharmony_ci
5517e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5518e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5519e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5520e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5521e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5522e41f4b71Sopenharmony_ci
5523e41f4b71Sopenharmony_ci**Example**
5524e41f4b71Sopenharmony_ci
5525e41f4b71Sopenharmony_ci```ts
5526e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5527e41f4b71Sopenharmony_ci
5528e41f4b71Sopenharmony_ciavsessionController.getLaunchAbility().then((agent: object) => {
5529e41f4b71Sopenharmony_ci  console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
5530e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5531e41f4b71Sopenharmony_ci  console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
5532e41f4b71Sopenharmony_ci});
5533e41f4b71Sopenharmony_ci```
5534e41f4b71Sopenharmony_ci
5535e41f4b71Sopenharmony_ci### getLaunchAbility<sup>10+</sup>
5536e41f4b71Sopenharmony_ci
5537e41f4b71Sopenharmony_cigetLaunchAbility(callback: AsyncCallback\<WantAgent>): void
5538e41f4b71Sopenharmony_ci
5539e41f4b71Sopenharmony_ciObtains the **WantAgent** object saved by the application in the session. This API uses an asynchronous callback to return the result.
5540e41f4b71Sopenharmony_ci
5541e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5542e41f4b71Sopenharmony_ci
5543e41f4b71Sopenharmony_ci**Parameters**
5544e41f4b71Sopenharmony_ci
5545e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
5546e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5547e41f4b71Sopenharmony_ci| callback | AsyncCallback<[WantAgent](../apis-ability-kit/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. |
5548e41f4b71Sopenharmony_ci
5549e41f4b71Sopenharmony_ci**Error codes**
5550e41f4b71Sopenharmony_ci
5551e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5552e41f4b71Sopenharmony_ci
5553e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5554e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5555e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5556e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5557e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5558e41f4b71Sopenharmony_ci
5559e41f4b71Sopenharmony_ci**Example**
5560e41f4b71Sopenharmony_ci
5561e41f4b71Sopenharmony_ci```ts
5562e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5563e41f4b71Sopenharmony_ci
5564e41f4b71Sopenharmony_ciavsessionController.getLaunchAbility((err: BusinessError, agent: object) => {
5565e41f4b71Sopenharmony_ci  if (err) {
5566e41f4b71Sopenharmony_ci    console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
5567e41f4b71Sopenharmony_ci  } else {
5568e41f4b71Sopenharmony_ci    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
5569e41f4b71Sopenharmony_ci  }
5570e41f4b71Sopenharmony_ci});
5571e41f4b71Sopenharmony_ci```
5572e41f4b71Sopenharmony_ci
5573e41f4b71Sopenharmony_ci### getRealPlaybackPositionSync<sup>10+</sup>
5574e41f4b71Sopenharmony_ci
5575e41f4b71Sopenharmony_cigetRealPlaybackPositionSync(): number
5576e41f4b71Sopenharmony_ci
5577e41f4b71Sopenharmony_ciObtains the playback position.
5578e41f4b71Sopenharmony_ci
5579e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5580e41f4b71Sopenharmony_ci
5581e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5582e41f4b71Sopenharmony_ci
5583e41f4b71Sopenharmony_ci**Return value**
5584e41f4b71Sopenharmony_ci
5585e41f4b71Sopenharmony_ci| Type   | Description                         |
5586e41f4b71Sopenharmony_ci| ------ | ----------------------------------- |
5587e41f4b71Sopenharmony_ci| number | Playback position, in milliseconds. |
5588e41f4b71Sopenharmony_ci
5589e41f4b71Sopenharmony_ci**Error codes**
5590e41f4b71Sopenharmony_ci
5591e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5592e41f4b71Sopenharmony_ci
5593e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5594e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5595e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5596e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5597e41f4b71Sopenharmony_ci
5598e41f4b71Sopenharmony_ci**Example**
5599e41f4b71Sopenharmony_ci
5600e41f4b71Sopenharmony_ci```ts
5601e41f4b71Sopenharmony_cilet time: number = avsessionController.getRealPlaybackPositionSync();
5602e41f4b71Sopenharmony_ci```
5603e41f4b71Sopenharmony_ci
5604e41f4b71Sopenharmony_ci### isActive<sup>10+</sup>
5605e41f4b71Sopenharmony_ci
5606e41f4b71Sopenharmony_ciisActive(): Promise\<boolean>
5607e41f4b71Sopenharmony_ci
5608e41f4b71Sopenharmony_ciChecks whether the session is activated. This API uses a promise to return the result.
5609e41f4b71Sopenharmony_ci
5610e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5611e41f4b71Sopenharmony_ci
5612e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5613e41f4b71Sopenharmony_ci
5614e41f4b71Sopenharmony_ci**Return value**
5615e41f4b71Sopenharmony_ci
5616e41f4b71Sopenharmony_ci| Type              | Description                                                  |
5617e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------------------------------ |
5618e41f4b71Sopenharmony_ci| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned. |
5619e41f4b71Sopenharmony_ci
5620e41f4b71Sopenharmony_ci**Error codes**
5621e41f4b71Sopenharmony_ci
5622e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5623e41f4b71Sopenharmony_ci
5624e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5625e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5626e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5627e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5628e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5629e41f4b71Sopenharmony_ci
5630e41f4b71Sopenharmony_ci**Example**
5631e41f4b71Sopenharmony_ci
5632e41f4b71Sopenharmony_ci```ts
5633e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5634e41f4b71Sopenharmony_ci
5635e41f4b71Sopenharmony_ciavsessionController.isActive().then((isActive: boolean) => {
5636e41f4b71Sopenharmony_ci  console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
5637e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5638e41f4b71Sopenharmony_ci  console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
5639e41f4b71Sopenharmony_ci});
5640e41f4b71Sopenharmony_ci```
5641e41f4b71Sopenharmony_ci
5642e41f4b71Sopenharmony_ci### isActive<sup>10+</sup>
5643e41f4b71Sopenharmony_ci
5644e41f4b71Sopenharmony_ciisActive(callback: AsyncCallback\<boolean>): void
5645e41f4b71Sopenharmony_ci
5646e41f4b71Sopenharmony_ciChecks whether the session is activated. This API uses an asynchronous callback to return the result.
5647e41f4b71Sopenharmony_ci
5648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5649e41f4b71Sopenharmony_ci
5650e41f4b71Sopenharmony_ci**Parameters**
5651e41f4b71Sopenharmony_ci
5652e41f4b71Sopenharmony_ci| Name     | Type                    | Mandatory | Description                                                  |
5653e41f4b71Sopenharmony_ci| -------- | ----------------------- | --------- | ------------------------------------------------------------ |
5654e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean\> | Yes       | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned. |
5655e41f4b71Sopenharmony_ci
5656e41f4b71Sopenharmony_ci**Error codes**
5657e41f4b71Sopenharmony_ci
5658e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5659e41f4b71Sopenharmony_ci
5660e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5661e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5662e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5663e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5664e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5665e41f4b71Sopenharmony_ci
5666e41f4b71Sopenharmony_ci**Example**
5667e41f4b71Sopenharmony_ci
5668e41f4b71Sopenharmony_ci```ts
5669e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5670e41f4b71Sopenharmony_ci
5671e41f4b71Sopenharmony_ciavsessionController.isActive((err: BusinessError, isActive: boolean) => {
5672e41f4b71Sopenharmony_ci  if (err) {
5673e41f4b71Sopenharmony_ci    console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
5674e41f4b71Sopenharmony_ci  } else {
5675e41f4b71Sopenharmony_ci    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
5676e41f4b71Sopenharmony_ci  }
5677e41f4b71Sopenharmony_ci});
5678e41f4b71Sopenharmony_ci```
5679e41f4b71Sopenharmony_ci
5680e41f4b71Sopenharmony_ci### destroy<sup>10+</sup>
5681e41f4b71Sopenharmony_ci
5682e41f4b71Sopenharmony_cidestroy(): Promise\<void>
5683e41f4b71Sopenharmony_ci
5684e41f4b71Sopenharmony_ciDestroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result.
5685e41f4b71Sopenharmony_ci
5686e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5687e41f4b71Sopenharmony_ci
5688e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5689e41f4b71Sopenharmony_ci
5690e41f4b71Sopenharmony_ci**Return value**
5691e41f4b71Sopenharmony_ci
5692e41f4b71Sopenharmony_ci| Type           | Description                                                  |
5693e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
5694e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned. |
5695e41f4b71Sopenharmony_ci
5696e41f4b71Sopenharmony_ci**Error codes**
5697e41f4b71Sopenharmony_ci
5698e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5699e41f4b71Sopenharmony_ci
5700e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5701e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5702e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5703e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5704e41f4b71Sopenharmony_ci
5705e41f4b71Sopenharmony_ci**Example**
5706e41f4b71Sopenharmony_ci
5707e41f4b71Sopenharmony_ci```ts
5708e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5709e41f4b71Sopenharmony_ci
5710e41f4b71Sopenharmony_ciavsessionController.destroy().then(() => {
5711e41f4b71Sopenharmony_ci  console.info('Destroy : SUCCESS ');
5712e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5713e41f4b71Sopenharmony_ci  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
5714e41f4b71Sopenharmony_ci});
5715e41f4b71Sopenharmony_ci```
5716e41f4b71Sopenharmony_ci
5717e41f4b71Sopenharmony_ci### destroy<sup>10+</sup>
5718e41f4b71Sopenharmony_ci
5719e41f4b71Sopenharmony_cidestroy(callback: AsyncCallback\<void>): void
5720e41f4b71Sopenharmony_ci
5721e41f4b71Sopenharmony_ciDestroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result.
5722e41f4b71Sopenharmony_ci
5723e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5724e41f4b71Sopenharmony_ci
5725e41f4b71Sopenharmony_ci**Parameters**
5726e41f4b71Sopenharmony_ci
5727e41f4b71Sopenharmony_ci| Name     | Type                 | Mandatory | Description                                                  |
5728e41f4b71Sopenharmony_ci| -------- | -------------------- | --------- | ------------------------------------------------------------ |
5729e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object. |
5730e41f4b71Sopenharmony_ci
5731e41f4b71Sopenharmony_ci**Error codes**
5732e41f4b71Sopenharmony_ci
5733e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5734e41f4b71Sopenharmony_ci
5735e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5736e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5737e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5738e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5739e41f4b71Sopenharmony_ci
5740e41f4b71Sopenharmony_ci**Example**
5741e41f4b71Sopenharmony_ci
5742e41f4b71Sopenharmony_ci```ts
5743e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5744e41f4b71Sopenharmony_ci
5745e41f4b71Sopenharmony_ciavsessionController.destroy((err: BusinessError) => {
5746e41f4b71Sopenharmony_ci  if (err) {
5747e41f4b71Sopenharmony_ci    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
5748e41f4b71Sopenharmony_ci  } else {
5749e41f4b71Sopenharmony_ci    console.info('Destroy : SUCCESS ');
5750e41f4b71Sopenharmony_ci  }
5751e41f4b71Sopenharmony_ci});
5752e41f4b71Sopenharmony_ci```
5753e41f4b71Sopenharmony_ci
5754e41f4b71Sopenharmony_ci### getValidCommands<sup>10+</sup>
5755e41f4b71Sopenharmony_ci
5756e41f4b71Sopenharmony_cigetValidCommands(): Promise\<Array\<AVControlCommandType>>
5757e41f4b71Sopenharmony_ci
5758e41f4b71Sopenharmony_ciObtains valid commands supported by the session. This API uses a promise to return the result.
5759e41f4b71Sopenharmony_ci
5760e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5761e41f4b71Sopenharmony_ci
5762e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5763e41f4b71Sopenharmony_ci
5764e41f4b71Sopenharmony_ci**Return value**
5765e41f4b71Sopenharmony_ci
5766e41f4b71Sopenharmony_ci| Type                                                         | Description                                     |
5767e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ----------------------------------------------- |
5768e41f4b71Sopenharmony_ci| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise used to return a set of valid commands. |
5769e41f4b71Sopenharmony_ci
5770e41f4b71Sopenharmony_ci**Error codes**
5771e41f4b71Sopenharmony_ci
5772e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5773e41f4b71Sopenharmony_ci
5774e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5775e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5776e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5777e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5778e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5779e41f4b71Sopenharmony_ci
5780e41f4b71Sopenharmony_ci**Example**
5781e41f4b71Sopenharmony_ci
5782e41f4b71Sopenharmony_ci```ts
5783e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5784e41f4b71Sopenharmony_ci
5785e41f4b71Sopenharmony_ciavsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => {
5786e41f4b71Sopenharmony_ci  console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
5787e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5788e41f4b71Sopenharmony_ci  console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
5789e41f4b71Sopenharmony_ci});
5790e41f4b71Sopenharmony_ci```
5791e41f4b71Sopenharmony_ci
5792e41f4b71Sopenharmony_ci### getValidCommands<sup>10+</sup>
5793e41f4b71Sopenharmony_ci
5794e41f4b71Sopenharmony_cigetValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void
5795e41f4b71Sopenharmony_ci
5796e41f4b71Sopenharmony_ciObtains valid commands supported by the session. This API uses an asynchronous callback to return the result.
5797e41f4b71Sopenharmony_ci
5798e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5799e41f4b71Sopenharmony_ci
5800e41f4b71Sopenharmony_ci**Parameters**
5801e41f4b71Sopenharmony_ci
5802e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                      |
5803e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------ |
5804e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Yes       | Callback used to return a set of valid commands. |
5805e41f4b71Sopenharmony_ci
5806e41f4b71Sopenharmony_ci**Error codes**
5807e41f4b71Sopenharmony_ci
5808e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5809e41f4b71Sopenharmony_ci
5810e41f4b71Sopenharmony_ci| ID      | Error Message                          |
5811e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
5812e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
5813e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
5814e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
5815e41f4b71Sopenharmony_ci
5816e41f4b71Sopenharmony_ci**Example**
5817e41f4b71Sopenharmony_ci
5818e41f4b71Sopenharmony_ci```ts
5819e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5820e41f4b71Sopenharmony_ci
5821e41f4b71Sopenharmony_ciavsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
5822e41f4b71Sopenharmony_ci  if (err) {
5823e41f4b71Sopenharmony_ci    console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
5824e41f4b71Sopenharmony_ci  } else {
5825e41f4b71Sopenharmony_ci    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
5826e41f4b71Sopenharmony_ci  }
5827e41f4b71Sopenharmony_ci});
5828e41f4b71Sopenharmony_ci```
5829e41f4b71Sopenharmony_ci
5830e41f4b71Sopenharmony_ci### sendControlCommand<sup>10+</sup>
5831e41f4b71Sopenharmony_ci
5832e41f4b71Sopenharmony_cisendControlCommand(command: AVControlCommand): Promise\<void>
5833e41f4b71Sopenharmony_ci
5834e41f4b71Sopenharmony_ciSends a control command to the session through the controller. This API uses a promise to return the result.
5835e41f4b71Sopenharmony_ci
5836e41f4b71Sopenharmony_ci> **NOTE**
5837e41f4b71Sopenharmony_ci>
5838e41f4b71Sopenharmony_ci> 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.
5839e41f4b71Sopenharmony_ci
5840e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5841e41f4b71Sopenharmony_ci
5842e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5843e41f4b71Sopenharmony_ci
5844e41f4b71Sopenharmony_ci**Parameters**
5845e41f4b71Sopenharmony_ci
5846e41f4b71Sopenharmony_ci| Name    | Type                                    | Mandatory | Description      |
5847e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | --------- | ---------------- |
5848e41f4b71Sopenharmony_ci| command | [AVControlCommand](#avcontrolcommand10) | Yes       | Command to send. |
5849e41f4b71Sopenharmony_ci
5850e41f4b71Sopenharmony_ci**Return value**
5851e41f4b71Sopenharmony_ci
5852e41f4b71Sopenharmony_ci| Type           | Description                                                  |
5853e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
5854e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. |
5855e41f4b71Sopenharmony_ci
5856e41f4b71Sopenharmony_ci**Error codes**
5857e41f4b71Sopenharmony_ci
5858e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5859e41f4b71Sopenharmony_ci
5860e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
5861e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
5862e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5863e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
5864e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
5865e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
5866e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
5867e41f4b71Sopenharmony_ci| 6600106 | The session is not activated.                                |
5868e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events.                                 |
5869e41f4b71Sopenharmony_ci
5870e41f4b71Sopenharmony_ci**Example**
5871e41f4b71Sopenharmony_ci
5872e41f4b71Sopenharmony_ci```ts
5873e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5874e41f4b71Sopenharmony_ci
5875e41f4b71Sopenharmony_cilet avCommand: avSession.AVControlCommand = {command:'play'};
5876e41f4b71Sopenharmony_ciavsessionController.sendControlCommand(avCommand).then(() => {
5877e41f4b71Sopenharmony_ci  console.info('SendControlCommand successfully');
5878e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
5879e41f4b71Sopenharmony_ci  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
5880e41f4b71Sopenharmony_ci});
5881e41f4b71Sopenharmony_ci```
5882e41f4b71Sopenharmony_ci
5883e41f4b71Sopenharmony_ci### sendControlCommand<sup>10+</sup>
5884e41f4b71Sopenharmony_ci
5885e41f4b71Sopenharmony_cisendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
5886e41f4b71Sopenharmony_ci
5887e41f4b71Sopenharmony_ciSends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
5888e41f4b71Sopenharmony_ci
5889e41f4b71Sopenharmony_ci> **NOTE**
5890e41f4b71Sopenharmony_ci>
5891e41f4b71Sopenharmony_ci> 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.
5892e41f4b71Sopenharmony_ci
5893e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5894e41f4b71Sopenharmony_ci
5895e41f4b71Sopenharmony_ci**Parameters**
5896e41f4b71Sopenharmony_ci
5897e41f4b71Sopenharmony_ci| Name     | Type                                    | Mandatory | Description                                                  |
5898e41f4b71Sopenharmony_ci| -------- | --------------------------------------- | --------- | ------------------------------------------------------------ |
5899e41f4b71Sopenharmony_ci| command  | [AVControlCommand](#avcontrolcommand10) | Yes       | Command to send.                                             |
5900e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                    | Yes       | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. |
5901e41f4b71Sopenharmony_ci
5902e41f4b71Sopenharmony_ci**Error codes**
5903e41f4b71Sopenharmony_ci
5904e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5905e41f4b71Sopenharmony_ci
5906e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
5907e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
5908e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5909e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
5910e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
5911e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
5912e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
5913e41f4b71Sopenharmony_ci| 6600106 | The session is not activated.                                |
5914e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events.                                 |
5915e41f4b71Sopenharmony_ci
5916e41f4b71Sopenharmony_ci**Example**
5917e41f4b71Sopenharmony_ci
5918e41f4b71Sopenharmony_ci```ts
5919e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5920e41f4b71Sopenharmony_ci
5921e41f4b71Sopenharmony_cilet avCommand: avSession.AVControlCommand = {command:'play'};
5922e41f4b71Sopenharmony_ciavsessionController.sendControlCommand(avCommand, (err: BusinessError) => {
5923e41f4b71Sopenharmony_ci  if (err) {
5924e41f4b71Sopenharmony_ci    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
5925e41f4b71Sopenharmony_ci  } else {
5926e41f4b71Sopenharmony_ci    console.info('SendControlCommand successfully');
5927e41f4b71Sopenharmony_ci  }
5928e41f4b71Sopenharmony_ci});
5929e41f4b71Sopenharmony_ci```
5930e41f4b71Sopenharmony_ci
5931e41f4b71Sopenharmony_ci### sendCommonCommand<sup>10+</sup>
5932e41f4b71Sopenharmony_ci
5933e41f4b71Sopenharmony_cisendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void>
5934e41f4b71Sopenharmony_ci
5935e41f4b71Sopenharmony_ciSends a custom control command to the session through the controller. This API uses a promise to return the result.
5936e41f4b71Sopenharmony_ci
5937e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5938e41f4b71Sopenharmony_ci
5939e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
5940e41f4b71Sopenharmony_ci
5941e41f4b71Sopenharmony_ci**Parameters**
5942e41f4b71Sopenharmony_ci
5943e41f4b71Sopenharmony_ci| Name    | Type                    | Mandatory | Description                                                  |
5944e41f4b71Sopenharmony_ci| ------- | ----------------------- | --------- | ------------------------------------------------------------ |
5945e41f4b71Sopenharmony_ci| command | string                  | Yes       | Name of the custom control command.                          |
5946e41f4b71Sopenharmony_ci| args    | {[key: string]: Object} | Yes       | Parameters in key-value pair format carried in the custom control command. |
5947e41f4b71Sopenharmony_ci
5948e41f4b71Sopenharmony_ci> **NOTE**
5949e41f4b71Sopenharmony_ci> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
5950e41f4b71Sopenharmony_ci
5951e41f4b71Sopenharmony_ci**Return value**
5952e41f4b71Sopenharmony_ci
5953e41f4b71Sopenharmony_ci| Type           | Description                                                  |
5954e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
5955e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. |
5956e41f4b71Sopenharmony_ci
5957e41f4b71Sopenharmony_ci**Error codes**
5958e41f4b71Sopenharmony_ci
5959e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5960e41f4b71Sopenharmony_ci
5961e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
5962e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
5963e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5964e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
5965e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
5966e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
5967e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
5968e41f4b71Sopenharmony_ci| 6600106 | The session is not activated.                                |
5969e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events.                                 |
5970e41f4b71Sopenharmony_ci
5971e41f4b71Sopenharmony_ci**Example**
5972e41f4b71Sopenharmony_ci
5973e41f4b71Sopenharmony_ci```ts
5974e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5975e41f4b71Sopenharmony_ci
5976e41f4b71Sopenharmony_cilet avSessionController: avSession.AVSessionController | undefined = undefined;
5977e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
5978e41f4b71Sopenharmony_cilet tag = "createNewSession";
5979e41f4b71Sopenharmony_cilet context: Context = getContext(this);
5980e41f4b71Sopenharmony_cilet sessionId: string = "";
5981e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
5982e41f4b71Sopenharmony_ci  if (err) {
5983e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
5984e41f4b71Sopenharmony_ci  } else {
5985e41f4b71Sopenharmony_ci    currentAVSession = data;
5986e41f4b71Sopenharmony_ci  }
5987e41f4b71Sopenharmony_ci});
5988e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
5989e41f4b71Sopenharmony_ci  sessionId = (currentAVSession as avSession.AVSession).sessionId;
5990e41f4b71Sopenharmony_ci  avSession.createController(sessionId).then((controller: avSession.AVSessionController) => {
5991e41f4b71Sopenharmony_ci    avSessionController = controller;
5992e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
5993e41f4b71Sopenharmony_ci    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
5994e41f4b71Sopenharmony_ci  });
5995e41f4b71Sopenharmony_ci}
5996e41f4b71Sopenharmony_ci
5997e41f4b71Sopenharmony_cilet commandName = "my_command";
5998e41f4b71Sopenharmony_ciif (avSessionController !== undefined) {
5999e41f4b71Sopenharmony_ci  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
6000e41f4b71Sopenharmony_ci    console.info('SendCommonCommand successfully');
6001e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
6002e41f4b71Sopenharmony_ci    console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6003e41f4b71Sopenharmony_ci  })
6004e41f4b71Sopenharmony_ci}
6005e41f4b71Sopenharmony_ci```
6006e41f4b71Sopenharmony_ci
6007e41f4b71Sopenharmony_ci### sendCommonCommand<sup>10+</sup>
6008e41f4b71Sopenharmony_ci
6009e41f4b71Sopenharmony_cisendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
6010e41f4b71Sopenharmony_ci
6011e41f4b71Sopenharmony_ciSends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result.
6012e41f4b71Sopenharmony_ci
6013e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6014e41f4b71Sopenharmony_ci
6015e41f4b71Sopenharmony_ci**Parameters**
6016e41f4b71Sopenharmony_ci
6017e41f4b71Sopenharmony_ci| Name     | Type                    | Mandatory | Description                                                  |
6018e41f4b71Sopenharmony_ci| -------- | ----------------------- | --------- | ------------------------------------------------------------ |
6019e41f4b71Sopenharmony_ci| command  | string                  | Yes       | Name of the custom control command.                          |
6020e41f4b71Sopenharmony_ci| args     | {[key: string]: Object} | Yes       | Parameters in key-value pair format carried in the custom control command. |
6021e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>    | Yes       | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. |
6022e41f4b71Sopenharmony_ci
6023e41f4b71Sopenharmony_ci> **NOTE**
6024e41f4b71Sopenharmony_ci> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
6025e41f4b71Sopenharmony_ci
6026e41f4b71Sopenharmony_ci**Error codes**
6027e41f4b71Sopenharmony_ci
6028e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6029e41f4b71Sopenharmony_ci
6030e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6031e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6032e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6033e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6034e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
6035e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6036e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
6037e41f4b71Sopenharmony_ci| 6600106 | The session is not activated.                                |
6038e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events.                                 |
6039e41f4b71Sopenharmony_ci
6040e41f4b71Sopenharmony_ci**Example**
6041e41f4b71Sopenharmony_ci
6042e41f4b71Sopenharmony_ci```ts
6043e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6044e41f4b71Sopenharmony_cilet avSessionController: avSession.AVSessionController | undefined = undefined;
6045e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
6046e41f4b71Sopenharmony_cilet tag = "createNewSession";
6047e41f4b71Sopenharmony_cilet context: Context = getContext(this);
6048e41f4b71Sopenharmony_ci
6049e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6050e41f4b71Sopenharmony_ci  if (err) {
6051e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6052e41f4b71Sopenharmony_ci  } else {
6053e41f4b71Sopenharmony_ci    currentAVSession = data;
6054e41f4b71Sopenharmony_ci  }
6055e41f4b71Sopenharmony_ci});
6056e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
6057e41f4b71Sopenharmony_ci  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6058e41f4b71Sopenharmony_ci    avSessionController = controller;
6059e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
6060e41f4b71Sopenharmony_ci    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6061e41f4b71Sopenharmony_ci  });
6062e41f4b71Sopenharmony_ci}
6063e41f4b71Sopenharmony_ci
6064e41f4b71Sopenharmony_cilet commandName = "my_command";
6065e41f4b71Sopenharmony_ciif (avSessionController !== undefined) {
6066e41f4b71Sopenharmony_ci  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
6067e41f4b71Sopenharmony_ci    if (err) {
6068e41f4b71Sopenharmony_ci        console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6069e41f4b71Sopenharmony_ci    }
6070e41f4b71Sopenharmony_ci  })
6071e41f4b71Sopenharmony_ci}
6072e41f4b71Sopenharmony_ci```
6073e41f4b71Sopenharmony_ci
6074e41f4b71Sopenharmony_ci### getExtras<sup>10+</sup>
6075e41f4b71Sopenharmony_ci
6076e41f4b71Sopenharmony_cigetExtras(): Promise\<{[key: string]: Object}>
6077e41f4b71Sopenharmony_ci
6078e41f4b71Sopenharmony_ciObtains the custom media packet set by the provider. This API uses a promise to return the result.
6079e41f4b71Sopenharmony_ci
6080e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6081e41f4b71Sopenharmony_ci
6082e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6083e41f4b71Sopenharmony_ci
6084e41f4b71Sopenharmony_ci**Return value**
6085e41f4b71Sopenharmony_ci
6086e41f4b71Sopenharmony_ci| Type                              | Description                                                  |
6087e41f4b71Sopenharmony_ci| --------------------------------- | ------------------------------------------------------------ |
6088e41f4b71Sopenharmony_ci| 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**. |
6089e41f4b71Sopenharmony_ci
6090e41f4b71Sopenharmony_ci**Error codes**
6091e41f4b71Sopenharmony_ci
6092e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6093e41f4b71Sopenharmony_ci
6094e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6095e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6096e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6097e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6098e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
6099e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6100e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
6101e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events.                                 |
6102e41f4b71Sopenharmony_ci
6103e41f4b71Sopenharmony_ci**Example**
6104e41f4b71Sopenharmony_ci
6105e41f4b71Sopenharmony_ci```ts
6106e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6107e41f4b71Sopenharmony_ci
6108e41f4b71Sopenharmony_cilet avSessionController: avSession.AVSessionController | undefined = undefined;
6109e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
6110e41f4b71Sopenharmony_cilet tag = "createNewSession";
6111e41f4b71Sopenharmony_cilet context: Context = getContext(this);
6112e41f4b71Sopenharmony_ci
6113e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6114e41f4b71Sopenharmony_ci  if (err) {
6115e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6116e41f4b71Sopenharmony_ci  } else {
6117e41f4b71Sopenharmony_ci    currentAVSession = data;
6118e41f4b71Sopenharmony_ci  }
6119e41f4b71Sopenharmony_ci});
6120e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
6121e41f4b71Sopenharmony_ci  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6122e41f4b71Sopenharmony_ci    avSessionController = controller;
6123e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
6124e41f4b71Sopenharmony_ci    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6125e41f4b71Sopenharmony_ci  });
6126e41f4b71Sopenharmony_ci}
6127e41f4b71Sopenharmony_ci
6128e41f4b71Sopenharmony_ciif (avSessionController !== undefined) {
6129e41f4b71Sopenharmony_ci  (avSessionController as avSession.AVSessionController).getExtras().then((extras) => {
6130e41f4b71Sopenharmony_ci    console.info(`getExtras : SUCCESS : ${extras}`);
6131e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
6132e41f4b71Sopenharmony_ci    console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6133e41f4b71Sopenharmony_ci  });
6134e41f4b71Sopenharmony_ci}
6135e41f4b71Sopenharmony_ci```
6136e41f4b71Sopenharmony_ci
6137e41f4b71Sopenharmony_ci### getExtras<sup>10+</sup>
6138e41f4b71Sopenharmony_ci
6139e41f4b71Sopenharmony_cigetExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
6140e41f4b71Sopenharmony_ci
6141e41f4b71Sopenharmony_ciObtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result.
6142e41f4b71Sopenharmony_ci
6143e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6144e41f4b71Sopenharmony_ci
6145e41f4b71Sopenharmony_ci**Parameters**
6146e41f4b71Sopenharmony_ci
6147e41f4b71Sopenharmony_ci| Name     | Type                                    | Mandatory | Description                                                  |
6148e41f4b71Sopenharmony_ci| -------- | --------------------------------------- | --------- | ------------------------------------------------------------ |
6149e41f4b71Sopenharmony_ci| 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**. |
6150e41f4b71Sopenharmony_ci
6151e41f4b71Sopenharmony_ci**Error codes**
6152e41f4b71Sopenharmony_ci
6153e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6154e41f4b71Sopenharmony_ci
6155e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6156e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6157e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6158e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6159e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.                                  |
6160e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6161e41f4b71Sopenharmony_ci| 6600105 | Invalid session command.                                     |
6162e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events.                                 |
6163e41f4b71Sopenharmony_ci
6164e41f4b71Sopenharmony_ci**Example**
6165e41f4b71Sopenharmony_ci
6166e41f4b71Sopenharmony_ci```ts
6167e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6168e41f4b71Sopenharmony_ci
6169e41f4b71Sopenharmony_cilet avSessionController: avSession.AVSessionController | undefined = undefined;
6170e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
6171e41f4b71Sopenharmony_cilet tag = "createNewSession";
6172e41f4b71Sopenharmony_cilet context: Context = getContext(this);
6173e41f4b71Sopenharmony_ci
6174e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6175e41f4b71Sopenharmony_ci  if (err) {
6176e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6177e41f4b71Sopenharmony_ci  } else {
6178e41f4b71Sopenharmony_ci    currentAVSession = data;
6179e41f4b71Sopenharmony_ci  }
6180e41f4b71Sopenharmony_ci});
6181e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
6182e41f4b71Sopenharmony_ci  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6183e41f4b71Sopenharmony_ci    avSessionController = controller;
6184e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
6185e41f4b71Sopenharmony_ci    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6186e41f4b71Sopenharmony_ci  });
6187e41f4b71Sopenharmony_ci}
6188e41f4b71Sopenharmony_ci
6189e41f4b71Sopenharmony_ciif (avSessionController !== undefined) {
6190e41f4b71Sopenharmony_ci  (avSessionController as avSession.AVSessionController).getExtras((err, extras) => {
6191e41f4b71Sopenharmony_ci    if (err) {
6192e41f4b71Sopenharmony_ci      console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6193e41f4b71Sopenharmony_ci    } else {
6194e41f4b71Sopenharmony_ci      console.info(`getExtras : SUCCESS : ${extras}`);
6195e41f4b71Sopenharmony_ci    }
6196e41f4b71Sopenharmony_ci  });
6197e41f4b71Sopenharmony_ci}
6198e41f4b71Sopenharmony_ci```
6199e41f4b71Sopenharmony_ci
6200e41f4b71Sopenharmony_ci### on('metadataChange')<sup>10+</sup>
6201e41f4b71Sopenharmony_ci
6202e41f4b71Sopenharmony_cion(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
6203e41f4b71Sopenharmony_ci
6204e41f4b71Sopenharmony_ciSubscribes to metadata change events.
6205e41f4b71Sopenharmony_ci
6206e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6207e41f4b71Sopenharmony_ci
6208e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6209e41f4b71Sopenharmony_ci
6210e41f4b71Sopenharmony_ci**Parameters**
6211e41f4b71Sopenharmony_ci
6212e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6213e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6214e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'metadataChange'** is triggered when the session metadata changes. |
6215e41f4b71Sopenharmony_ci| 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. |
6216e41f4b71Sopenharmony_ci| callback | (data: [AVMetadata](#avmetadata10)) => void                  | Yes       | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata. |
6217e41f4b71Sopenharmony_ci
6218e41f4b71Sopenharmony_ci**Error codes**
6219e41f4b71Sopenharmony_ci
6220e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6221e41f4b71Sopenharmony_ci
6222e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6223e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6224e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6225e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6226e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6227e41f4b71Sopenharmony_ci
6228e41f4b71Sopenharmony_ci**Example**
6229e41f4b71Sopenharmony_ci
6230e41f4b71Sopenharmony_ci```ts
6231e41f4b71Sopenharmony_ciavsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
6232e41f4b71Sopenharmony_ci  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6233e41f4b71Sopenharmony_ci});
6234e41f4b71Sopenharmony_ci
6235e41f4b71Sopenharmony_ciavsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
6236e41f4b71Sopenharmony_ci  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6237e41f4b71Sopenharmony_ci});
6238e41f4b71Sopenharmony_ci
6239e41f4b71Sopenharmony_ci```
6240e41f4b71Sopenharmony_ci
6241e41f4b71Sopenharmony_ci### off('metadataChange')<sup>10+</sup>
6242e41f4b71Sopenharmony_ci
6243e41f4b71Sopenharmony_cioff(type: 'metadataChange', callback?: (data: AVMetadata) => void)
6244e41f4b71Sopenharmony_ci
6245e41f4b71Sopenharmony_ciUnsubscribes from metadata change events. This API is called by the controller.
6246e41f4b71Sopenharmony_ci
6247e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6248e41f4b71Sopenharmony_ci
6249e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6250e41f4b71Sopenharmony_ci
6251e41f4b71Sopenharmony_ci**Parameters**
6252e41f4b71Sopenharmony_ci
6253e41f4b71Sopenharmony_ci| Name     | Type                                        | Mandatory | Description                                                  |
6254e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | --------- | ------------------------------------------------------------ |
6255e41f4b71Sopenharmony_ci| type     | string                                      | Yes       | Event type, which is **'metadataChange'** in this case.      |
6256e41f4b71Sopenharmony_ci| 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. |
6257e41f4b71Sopenharmony_ci
6258e41f4b71Sopenharmony_ci**Error codes**
6259e41f4b71Sopenharmony_ci
6260e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6261e41f4b71Sopenharmony_ci
6262e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6263e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6264e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6265e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6266e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6267e41f4b71Sopenharmony_ci
6268e41f4b71Sopenharmony_ci**Example**
6269e41f4b71Sopenharmony_ci
6270e41f4b71Sopenharmony_ci```ts
6271e41f4b71Sopenharmony_ciavsessionController.off('metadataChange');
6272e41f4b71Sopenharmony_ci```
6273e41f4b71Sopenharmony_ci
6274e41f4b71Sopenharmony_ci### on('playbackStateChange')<sup>10+</sup>
6275e41f4b71Sopenharmony_ci
6276e41f4b71Sopenharmony_cion(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
6277e41f4b71Sopenharmony_ci
6278e41f4b71Sopenharmony_ciSubscribes to playback state change events.
6279e41f4b71Sopenharmony_ci
6280e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6281e41f4b71Sopenharmony_ci
6282e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6283e41f4b71Sopenharmony_ci
6284e41f4b71Sopenharmony_ci**Parameters**
6285e41f4b71Sopenharmony_ci
6286e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6287e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6288e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'playbackStateChange'** is triggered when the playback state changes. |
6289e41f4b71Sopenharmony_ci| 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. |
6290e41f4b71Sopenharmony_ci| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void       | Yes       | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state. |
6291e41f4b71Sopenharmony_ci
6292e41f4b71Sopenharmony_ci**Error codes**
6293e41f4b71Sopenharmony_ci
6294e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6295e41f4b71Sopenharmony_ci
6296e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6297e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6298e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6299e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6300e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6301e41f4b71Sopenharmony_ci
6302e41f4b71Sopenharmony_ci**Example**
6303e41f4b71Sopenharmony_ci
6304e41f4b71Sopenharmony_ci```ts
6305e41f4b71Sopenharmony_ciavsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
6306e41f4b71Sopenharmony_ci  console.info(`on playbackStateChange state : ${playbackState.state}`);
6307e41f4b71Sopenharmony_ci});
6308e41f4b71Sopenharmony_ci
6309e41f4b71Sopenharmony_ciavsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
6310e41f4b71Sopenharmony_ci  console.info(`on playbackStateChange state : ${playbackState.state}`);
6311e41f4b71Sopenharmony_ci});
6312e41f4b71Sopenharmony_ci```
6313e41f4b71Sopenharmony_ci
6314e41f4b71Sopenharmony_ci### off('playbackStateChange')<sup>10+</sup>
6315e41f4b71Sopenharmony_ci
6316e41f4b71Sopenharmony_cioff(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
6317e41f4b71Sopenharmony_ci
6318e41f4b71Sopenharmony_ciUnsubscribes from playback state change events. This API is called by the controller.
6319e41f4b71Sopenharmony_ci
6320e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6321e41f4b71Sopenharmony_ci
6322e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6323e41f4b71Sopenharmony_ci
6324e41f4b71Sopenharmony_ci**Parameters**
6325e41f4b71Sopenharmony_ci
6326e41f4b71Sopenharmony_ci| Name     | Type                                                   | Mandatory | Description                                                  |
6327e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6328e41f4b71Sopenharmony_ci| type     | string                                                 | Yes       | Event type, which is **'playbackStateChange'** in this case. |
6329e41f4b71Sopenharmony_ci| 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. |
6330e41f4b71Sopenharmony_ci
6331e41f4b71Sopenharmony_ci**Error codes**
6332e41f4b71Sopenharmony_ci
6333e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6334e41f4b71Sopenharmony_ci
6335e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6336e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6337e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6338e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6339e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6340e41f4b71Sopenharmony_ci
6341e41f4b71Sopenharmony_ci**Example**
6342e41f4b71Sopenharmony_ci
6343e41f4b71Sopenharmony_ci```ts
6344e41f4b71Sopenharmony_ciavsessionController.off('playbackStateChange');
6345e41f4b71Sopenharmony_ci```
6346e41f4b71Sopenharmony_ci
6347e41f4b71Sopenharmony_ci### on('callMetadataChange')<sup>11+</sup>
6348e41f4b71Sopenharmony_ci
6349e41f4b71Sopenharmony_cion(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void;
6350e41f4b71Sopenharmony_ci
6351e41f4b71Sopenharmony_ciSubscribes to call metadata change events.
6352e41f4b71Sopenharmony_ci
6353e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6354e41f4b71Sopenharmony_ci
6355e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6356e41f4b71Sopenharmony_ci
6357e41f4b71Sopenharmony_ci**Parameters**
6358e41f4b71Sopenharmony_ci
6359e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6360e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6361e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'callMetadataChange'** is triggered when the call metadata changes. |
6362e41f4b71Sopenharmony_ci| filter   | Array\<keyof&nbsp;[CallMetadata](#callmetadata11)\>&nbsp;&#124;&nbsp;'all' | Yes       | The value **'all'** indicates that any call metadata field change will trigger the event, and **Array<keyof&nbsp;[CallMetadata](#callmetadata11)\>** indicates that only changes to the listed metadata field will trigger the event. |
6363e41f4b71Sopenharmony_ci| callback | Callback<[CallMetadata](#callmetadata11)\>\>                 | Yes       | Callback used for subscription. The **callmetadata** parameter in the callback indicates the changed call metadata. |
6364e41f4b71Sopenharmony_ci
6365e41f4b71Sopenharmony_ci**Error codes**
6366e41f4b71Sopenharmony_ci
6367e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6368e41f4b71Sopenharmony_ci
6369e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6370e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6371e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6372e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6373e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6374e41f4b71Sopenharmony_ci
6375e41f4b71Sopenharmony_ci**Example**
6376e41f4b71Sopenharmony_ci
6377e41f4b71Sopenharmony_ci```ts
6378e41f4b71Sopenharmony_ciavsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => {
6379e41f4b71Sopenharmony_ci  console.info(`on callMetadataChange state : ${callmetadata.name}`);
6380e41f4b71Sopenharmony_ci});
6381e41f4b71Sopenharmony_ci
6382e41f4b71Sopenharmony_ciavsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => {
6383e41f4b71Sopenharmony_ci  console.info(`on callMetadataChange state : ${callmetadata.name}`);
6384e41f4b71Sopenharmony_ci});
6385e41f4b71Sopenharmony_ci```
6386e41f4b71Sopenharmony_ci
6387e41f4b71Sopenharmony_ci### off('callMetadataChange')<sup>11+</sup>
6388e41f4b71Sopenharmony_ci
6389e41f4b71Sopenharmony_cioff(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void;
6390e41f4b71Sopenharmony_ci
6391e41f4b71Sopenharmony_ciUnsubscribes from call metadata change events.
6392e41f4b71Sopenharmony_ci
6393e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6394e41f4b71Sopenharmony_ci
6395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6396e41f4b71Sopenharmony_ci
6397e41f4b71Sopenharmony_ci**Parameters**
6398e41f4b71Sopenharmony_ci
6399e41f4b71Sopenharmony_ci| Name     | Type                                       | Mandatory | Description                                                  |
6400e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ | --------- | ------------------------------------------------------------ |
6401e41f4b71Sopenharmony_ci| type     | string                                     | Yes       | Event type, which is **'callMetadataChange'** in this case.  |
6402e41f4b71Sopenharmony_ci| callback | Callback<[CallMetadata](#callmetadata11)\> | No        | Callback used for unsubscription. The **calldata** parameter in the callback indicates the changed call metadata.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
6403e41f4b71Sopenharmony_ci
6404e41f4b71Sopenharmony_ci**Error codes**
6405e41f4b71Sopenharmony_ci
6406e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6407e41f4b71Sopenharmony_ci
6408e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6409e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6410e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6411e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6412e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6413e41f4b71Sopenharmony_ci
6414e41f4b71Sopenharmony_ci**Example**
6415e41f4b71Sopenharmony_ci
6416e41f4b71Sopenharmony_ci```ts
6417e41f4b71Sopenharmony_ciavsessionController.off('callMetadataChange');
6418e41f4b71Sopenharmony_ci```
6419e41f4b71Sopenharmony_ci
6420e41f4b71Sopenharmony_ci### on('callStateChange')<sup>11+</sup>
6421e41f4b71Sopenharmony_ci
6422e41f4b71Sopenharmony_cion(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void;
6423e41f4b71Sopenharmony_ci
6424e41f4b71Sopenharmony_ciSubscribes to call state change events.
6425e41f4b71Sopenharmony_ci
6426e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6427e41f4b71Sopenharmony_ci
6428e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6429e41f4b71Sopenharmony_ci
6430e41f4b71Sopenharmony_ci**Parameters**
6431e41f4b71Sopenharmony_ci
6432e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6433e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6434e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'callStateChange'** is triggered when the call state changes. |
6435e41f4b71Sopenharmony_ci| filter   | Array<keyof&nbsp;[AVCallState](#avcallstate11)\>&nbsp;&#124;&nbsp;'all' | Yes       | The value **'all'** indicates that any call state field change will trigger the event, and **Array<keyof&nbsp;[AVCallState](#avcallstate11)\>** indicates that only changes to the listed call state field will trigger the event. |
6436e41f4b71Sopenharmony_ci| callback | Callback<[AVCallState](#avcallstate11)\>                     | Yes       | Callback used for subscription. The **callstate** parameter in the callback indicates the changed call state. |
6437e41f4b71Sopenharmony_ci
6438e41f4b71Sopenharmony_ci**Error codes**
6439e41f4b71Sopenharmony_ci
6440e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6441e41f4b71Sopenharmony_ci
6442e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6443e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6444e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6445e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6446e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6447e41f4b71Sopenharmony_ci
6448e41f4b71Sopenharmony_ci**Example**
6449e41f4b71Sopenharmony_ci
6450e41f4b71Sopenharmony_ci```ts
6451e41f4b71Sopenharmony_ciavsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => {
6452e41f4b71Sopenharmony_ci  console.info(`on callStateChange state : ${callstate.state}`);
6453e41f4b71Sopenharmony_ci});
6454e41f4b71Sopenharmony_ci
6455e41f4b71Sopenharmony_ciavsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => {
6456e41f4b71Sopenharmony_ci  console.info(`on callStateChange state : ${callstate.state}`);
6457e41f4b71Sopenharmony_ci});
6458e41f4b71Sopenharmony_ci```
6459e41f4b71Sopenharmony_ci
6460e41f4b71Sopenharmony_ci### off('callStateChange')<sup>11+</sup>
6461e41f4b71Sopenharmony_ci
6462e41f4b71Sopenharmony_cioff(type: 'callStateChange', callback?: Callback\<AVCallState>): void;
6463e41f4b71Sopenharmony_ci
6464e41f4b71Sopenharmony_ciUnsubscribes from call state change events.
6465e41f4b71Sopenharmony_ci
6466e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6467e41f4b71Sopenharmony_ci
6468e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6469e41f4b71Sopenharmony_ci
6470e41f4b71Sopenharmony_ci**Parameters**
6471e41f4b71Sopenharmony_ci
6472e41f4b71Sopenharmony_ci| Name     | Type                                     | Mandatory | Description                                                  |
6473e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ |
6474e41f4b71Sopenharmony_ci| type     | string                                   | Yes       | Event type, which is **'callStateChange'** in this case.     |
6475e41f4b71Sopenharmony_ci| callback | Callback<[AVCallState](#avcallstate11)\> | No        | Callback used for unsubscription. The **callstate** parameter in the callback indicates the changed call metadata.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
6476e41f4b71Sopenharmony_ci
6477e41f4b71Sopenharmony_ci**Error codes**
6478e41f4b71Sopenharmony_ci
6479e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6480e41f4b71Sopenharmony_ci
6481e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6482e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6483e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6484e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6485e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6486e41f4b71Sopenharmony_ci
6487e41f4b71Sopenharmony_ci**Example**
6488e41f4b71Sopenharmony_ci
6489e41f4b71Sopenharmony_ci```ts
6490e41f4b71Sopenharmony_ciavsessionController.off('callMetadataChange');
6491e41f4b71Sopenharmony_ci```
6492e41f4b71Sopenharmony_ci
6493e41f4b71Sopenharmony_ci### on('sessionDestroy')<sup>10+</sup>
6494e41f4b71Sopenharmony_ci
6495e41f4b71Sopenharmony_cion(type: 'sessionDestroy', callback: () => void)
6496e41f4b71Sopenharmony_ci
6497e41f4b71Sopenharmony_ciSubscribes to session destruction events.
6498e41f4b71Sopenharmony_ci
6499e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6500e41f4b71Sopenharmony_ci
6501e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6502e41f4b71Sopenharmony_ci
6503e41f4b71Sopenharmony_ci**Parameters**
6504e41f4b71Sopenharmony_ci
6505e41f4b71Sopenharmony_ci| Name     | Type       | Mandatory | Description                                                  |
6506e41f4b71Sopenharmony_ci| -------- | ---------- | --------- | ------------------------------------------------------------ |
6507e41f4b71Sopenharmony_ci| type     | string     | Yes       | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed. |
6508e41f4b71Sopenharmony_ci| callback | () => void | Yes       | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. |
6509e41f4b71Sopenharmony_ci
6510e41f4b71Sopenharmony_ci**Error codes**
6511e41f4b71Sopenharmony_ci
6512e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6513e41f4b71Sopenharmony_ci
6514e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6515e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6516e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6517e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6518e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6519e41f4b71Sopenharmony_ci
6520e41f4b71Sopenharmony_ci**Example**
6521e41f4b71Sopenharmony_ci
6522e41f4b71Sopenharmony_ci```ts
6523e41f4b71Sopenharmony_ciavsessionController.on('sessionDestroy', () => {
6524e41f4b71Sopenharmony_ci  console.info('on sessionDestroy : SUCCESS ');
6525e41f4b71Sopenharmony_ci});
6526e41f4b71Sopenharmony_ci```
6527e41f4b71Sopenharmony_ci
6528e41f4b71Sopenharmony_ci### off('sessionDestroy')<sup>10+</sup>
6529e41f4b71Sopenharmony_ci
6530e41f4b71Sopenharmony_cioff(type: 'sessionDestroy', callback?: () => void)
6531e41f4b71Sopenharmony_ci
6532e41f4b71Sopenharmony_ciUnsubscribes from session destruction events. This API is called by the controller.
6533e41f4b71Sopenharmony_ci
6534e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6535e41f4b71Sopenharmony_ci
6536e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6537e41f4b71Sopenharmony_ci
6538e41f4b71Sopenharmony_ci**Parameters**
6539e41f4b71Sopenharmony_ci
6540e41f4b71Sopenharmony_ci| Name     | Type       | Mandatory | Description                                                  |
6541e41f4b71Sopenharmony_ci| -------- | ---------- | --------- | ------------------------------------------------------------ |
6542e41f4b71Sopenharmony_ci| type     | string     | Yes       | Event type, which is **'sessionDestroy'** in this case.      |
6543e41f4b71Sopenharmony_ci| 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. |
6544e41f4b71Sopenharmony_ci
6545e41f4b71Sopenharmony_ci**Error codes**
6546e41f4b71Sopenharmony_ci
6547e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6548e41f4b71Sopenharmony_ci
6549e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6550e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6551e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6552e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6553e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6554e41f4b71Sopenharmony_ci
6555e41f4b71Sopenharmony_ci**Example**
6556e41f4b71Sopenharmony_ci
6557e41f4b71Sopenharmony_ci```ts
6558e41f4b71Sopenharmony_ciavsessionController.off('sessionDestroy');
6559e41f4b71Sopenharmony_ci```
6560e41f4b71Sopenharmony_ci
6561e41f4b71Sopenharmony_ci### on('activeStateChange')<sup>10+</sup>
6562e41f4b71Sopenharmony_ci
6563e41f4b71Sopenharmony_cion(type: 'activeStateChange', callback: (isActive: boolean) => void)
6564e41f4b71Sopenharmony_ci
6565e41f4b71Sopenharmony_ciSubscribes to session activation state change events.
6566e41f4b71Sopenharmony_ci
6567e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6568e41f4b71Sopenharmony_ci
6569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6570e41f4b71Sopenharmony_ci
6571e41f4b71Sopenharmony_ci**Parameters**
6572e41f4b71Sopenharmony_ci
6573e41f4b71Sopenharmony_ci| Name     | Type                        | Mandatory | Description                                                  |
6574e41f4b71Sopenharmony_ci| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
6575e41f4b71Sopenharmony_ci| type     | string                      | Yes       | Event type. The event **'activeStateChange'** is triggered when the activation state of the session changes. |
6576e41f4b71Sopenharmony_ci| 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. |
6577e41f4b71Sopenharmony_ci
6578e41f4b71Sopenharmony_ci**Error codes**
6579e41f4b71Sopenharmony_ci
6580e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6581e41f4b71Sopenharmony_ci
6582e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6583e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6584e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6585e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6586e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6587e41f4b71Sopenharmony_ci
6588e41f4b71Sopenharmony_ci**Example**
6589e41f4b71Sopenharmony_ci
6590e41f4b71Sopenharmony_ci```ts
6591e41f4b71Sopenharmony_ciavsessionController.on('activeStateChange', (isActive: boolean) => {
6592e41f4b71Sopenharmony_ci  console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
6593e41f4b71Sopenharmony_ci});
6594e41f4b71Sopenharmony_ci```
6595e41f4b71Sopenharmony_ci
6596e41f4b71Sopenharmony_ci### off('activeStateChange')<sup>10+</sup>
6597e41f4b71Sopenharmony_ci
6598e41f4b71Sopenharmony_cioff(type: 'activeStateChange', callback?: (isActive: boolean) => void)
6599e41f4b71Sopenharmony_ci
6600e41f4b71Sopenharmony_ciUnsubscribes from session activation state change events. This API is called by the controller.
6601e41f4b71Sopenharmony_ci
6602e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6603e41f4b71Sopenharmony_ci
6604e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6605e41f4b71Sopenharmony_ci
6606e41f4b71Sopenharmony_ci**Parameters**
6607e41f4b71Sopenharmony_ci
6608e41f4b71Sopenharmony_ci| Name     | Type                        | Mandatory | Description                                                  |
6609e41f4b71Sopenharmony_ci| -------- | --------------------------- | --------- | ------------------------------------------------------------ |
6610e41f4b71Sopenharmony_ci| type     | string                      | Yes       | Event type, which is **'activeStateChange'** in this case.   |
6611e41f4b71Sopenharmony_ci| 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. |
6612e41f4b71Sopenharmony_ci
6613e41f4b71Sopenharmony_ci**Error codes**
6614e41f4b71Sopenharmony_ci
6615e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6616e41f4b71Sopenharmony_ci
6617e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6618e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6619e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6620e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6621e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6622e41f4b71Sopenharmony_ci
6623e41f4b71Sopenharmony_ci**Example**
6624e41f4b71Sopenharmony_ci
6625e41f4b71Sopenharmony_ci```ts
6626e41f4b71Sopenharmony_ciavsessionController.off('activeStateChange');
6627e41f4b71Sopenharmony_ci```
6628e41f4b71Sopenharmony_ci
6629e41f4b71Sopenharmony_ci### on('validCommandChange')<sup>10+</sup>
6630e41f4b71Sopenharmony_ci
6631e41f4b71Sopenharmony_cion(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void)
6632e41f4b71Sopenharmony_ci
6633e41f4b71Sopenharmony_ciSubscribes to valid command change events.
6634e41f4b71Sopenharmony_ci
6635e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6636e41f4b71Sopenharmony_ci
6637e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6638e41f4b71Sopenharmony_ci
6639e41f4b71Sopenharmony_ci**Parameters**
6640e41f4b71Sopenharmony_ci
6641e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6642e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6643e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes. |
6644e41f4b71Sopenharmony_ci| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes       | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. |
6645e41f4b71Sopenharmony_ci
6646e41f4b71Sopenharmony_ci**Error codes**
6647e41f4b71Sopenharmony_ci
6648e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6649e41f4b71Sopenharmony_ci
6650e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6651e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6652e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6653e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6654e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6655e41f4b71Sopenharmony_ci
6656e41f4b71Sopenharmony_ci**Example**
6657e41f4b71Sopenharmony_ci
6658e41f4b71Sopenharmony_ci```ts
6659e41f4b71Sopenharmony_ciavsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
6660e41f4b71Sopenharmony_ci  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
6661e41f4b71Sopenharmony_ci  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
6662e41f4b71Sopenharmony_ci});
6663e41f4b71Sopenharmony_ci```
6664e41f4b71Sopenharmony_ci
6665e41f4b71Sopenharmony_ci### off('validCommandChange')<sup>10+</sup>
6666e41f4b71Sopenharmony_ci
6667e41f4b71Sopenharmony_cioff(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void)
6668e41f4b71Sopenharmony_ci
6669e41f4b71Sopenharmony_ciUnsubscribes from valid command change events. This API is called by the controller.
6670e41f4b71Sopenharmony_ci
6671e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6672e41f4b71Sopenharmony_ci
6673e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6674e41f4b71Sopenharmony_ci
6675e41f4b71Sopenharmony_ci**Parameters**
6676e41f4b71Sopenharmony_ci
6677e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6678e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6679e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type, which is **'validCommandChange'** in this case.  |
6680e41f4b71Sopenharmony_ci| 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. |
6681e41f4b71Sopenharmony_ci
6682e41f4b71Sopenharmony_ci**Error codes**
6683e41f4b71Sopenharmony_ci
6684e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6685e41f4b71Sopenharmony_ci
6686e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6687e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6688e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6689e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6690e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6691e41f4b71Sopenharmony_ci
6692e41f4b71Sopenharmony_ci**Example**
6693e41f4b71Sopenharmony_ci
6694e41f4b71Sopenharmony_ci```ts
6695e41f4b71Sopenharmony_ciavsessionController.off('validCommandChange');
6696e41f4b71Sopenharmony_ci```
6697e41f4b71Sopenharmony_ci
6698e41f4b71Sopenharmony_ci### on('outputDeviceChange')<sup>10+</sup>
6699e41f4b71Sopenharmony_ci
6700e41f4b71Sopenharmony_cion(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
6701e41f4b71Sopenharmony_ci
6702e41f4b71Sopenharmony_ciSubscribes to output device change events.
6703e41f4b71Sopenharmony_ci
6704e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6705e41f4b71Sopenharmony_ci
6706e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6707e41f4b71Sopenharmony_ci
6708e41f4b71Sopenharmony_ci**Parameters**
6709e41f4b71Sopenharmony_ci
6710e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6711e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6712e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'outputDeviceChange'** is triggered when the output device changes. |
6713e41f4b71Sopenharmony_ci| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes       | Callback used for subscription. The **device** parameter in the callback indicates the output device information. |
6714e41f4b71Sopenharmony_ci
6715e41f4b71Sopenharmony_ci**Error codes**
6716e41f4b71Sopenharmony_ci
6717e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6718e41f4b71Sopenharmony_ci
6719e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6720e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6721e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6722e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6723e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6724e41f4b71Sopenharmony_ci
6725e41f4b71Sopenharmony_ci**Example**
6726e41f4b71Sopenharmony_ci
6727e41f4b71Sopenharmony_ci```ts
6728e41f4b71Sopenharmony_ciavsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
6729e41f4b71Sopenharmony_ci  console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
6730e41f4b71Sopenharmony_ci});
6731e41f4b71Sopenharmony_ci```
6732e41f4b71Sopenharmony_ci
6733e41f4b71Sopenharmony_ci### off('outputDeviceChange')<sup>10+</sup>
6734e41f4b71Sopenharmony_ci
6735e41f4b71Sopenharmony_cioff(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
6736e41f4b71Sopenharmony_ci
6737e41f4b71Sopenharmony_ciUnsubscribes from output device change events. This API is called by the controller.
6738e41f4b71Sopenharmony_ci
6739e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6740e41f4b71Sopenharmony_ci
6741e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6742e41f4b71Sopenharmony_ci
6743e41f4b71Sopenharmony_ci**Parameters**
6744e41f4b71Sopenharmony_ci
6745e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6746e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6747e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type, which is **'outputDeviceChange'** in this case.  |
6748e41f4b71Sopenharmony_ci| 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. |
6749e41f4b71Sopenharmony_ci
6750e41f4b71Sopenharmony_ci**Error codes**
6751e41f4b71Sopenharmony_ci
6752e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6753e41f4b71Sopenharmony_ci
6754e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6755e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6756e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6757e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6758e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6759e41f4b71Sopenharmony_ci
6760e41f4b71Sopenharmony_ci**Example**
6761e41f4b71Sopenharmony_ci
6762e41f4b71Sopenharmony_ci```ts
6763e41f4b71Sopenharmony_ciavsessionController.off('outputDeviceChange');
6764e41f4b71Sopenharmony_ci```
6765e41f4b71Sopenharmony_ci
6766e41f4b71Sopenharmony_ci### on('sessionEvent')<sup>10+</sup>
6767e41f4b71Sopenharmony_ci
6768e41f4b71Sopenharmony_cion(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void
6769e41f4b71Sopenharmony_ci
6770e41f4b71Sopenharmony_ciSubscribes to session event change events. This API is called by the controller.
6771e41f4b71Sopenharmony_ci
6772e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6773e41f4b71Sopenharmony_ci
6774e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6775e41f4b71Sopenharmony_ci
6776e41f4b71Sopenharmony_ci**Parameters**
6777e41f4b71Sopenharmony_ci
6778e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6779e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6780e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type. The event **'sessionEvent'** is triggered when the session event changes. |
6781e41f4b71Sopenharmony_ci| 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. |
6782e41f4b71Sopenharmony_ci
6783e41f4b71Sopenharmony_ci**Error codes**
6784e41f4b71Sopenharmony_ci
6785e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6786e41f4b71Sopenharmony_ci
6787e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6788e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6789e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6790e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6791e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6792e41f4b71Sopenharmony_ci
6793e41f4b71Sopenharmony_ci**Example**
6794e41f4b71Sopenharmony_ci
6795e41f4b71Sopenharmony_ci```ts
6796e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
6797e41f4b71Sopenharmony_ci
6798e41f4b71Sopenharmony_cilet avSessionController: avSession.AVSessionController | undefined = undefined;
6799e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
6800e41f4b71Sopenharmony_cilet tag = "createNewSession";
6801e41f4b71Sopenharmony_cilet context: Context = getContext(this);
6802e41f4b71Sopenharmony_ci
6803e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6804e41f4b71Sopenharmony_ci  if (err) {
6805e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6806e41f4b71Sopenharmony_ci  } else {
6807e41f4b71Sopenharmony_ci    currentAVSession = data;
6808e41f4b71Sopenharmony_ci  }
6809e41f4b71Sopenharmony_ci});
6810e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
6811e41f4b71Sopenharmony_ci  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6812e41f4b71Sopenharmony_ci    avSessionController = controller;
6813e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
6814e41f4b71Sopenharmony_ci    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6815e41f4b71Sopenharmony_ci  });
6816e41f4b71Sopenharmony_ci}
6817e41f4b71Sopenharmony_ci
6818e41f4b71Sopenharmony_ciif (avSessionController !== undefined) {
6819e41f4b71Sopenharmony_ci  (avSessionController as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => {
6820e41f4b71Sopenharmony_ci    console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
6821e41f4b71Sopenharmony_ci  });
6822e41f4b71Sopenharmony_ci}
6823e41f4b71Sopenharmony_ci```
6824e41f4b71Sopenharmony_ci
6825e41f4b71Sopenharmony_ci### off('sessionEvent')<sup>10+</sup>
6826e41f4b71Sopenharmony_ci
6827e41f4b71Sopenharmony_cioff(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void
6828e41f4b71Sopenharmony_ci
6829e41f4b71Sopenharmony_ciUnsubscribes from session event change events. This API is called by the controller.
6830e41f4b71Sopenharmony_ci
6831e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6832e41f4b71Sopenharmony_ci
6833e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6834e41f4b71Sopenharmony_ci
6835e41f4b71Sopenharmony_ci**Parameters**
6836e41f4b71Sopenharmony_ci
6837e41f4b71Sopenharmony_ci| Name     | Type                                                         | Mandatory | Description                                                  |
6838e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6839e41f4b71Sopenharmony_ci| type     | string                                                       | Yes       | Event type, which is **'sessionEvent'** in this case.        |
6840e41f4b71Sopenharmony_ci| 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. |
6841e41f4b71Sopenharmony_ci
6842e41f4b71Sopenharmony_ci**Error codes**
6843e41f4b71Sopenharmony_ci
6844e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6845e41f4b71Sopenharmony_ci
6846e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6847e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6848e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6849e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6850e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6851e41f4b71Sopenharmony_ci
6852e41f4b71Sopenharmony_ci**Example**
6853e41f4b71Sopenharmony_ci
6854e41f4b71Sopenharmony_ci```ts
6855e41f4b71Sopenharmony_ciavsessionController.off('sessionEvent');
6856e41f4b71Sopenharmony_ci```
6857e41f4b71Sopenharmony_ci
6858e41f4b71Sopenharmony_ci### on('queueItemsChange')<sup>10+</sup>
6859e41f4b71Sopenharmony_ci
6860e41f4b71Sopenharmony_cion(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
6861e41f4b71Sopenharmony_ci
6862e41f4b71Sopenharmony_ciSubscribes to playlist item change events. This API is called by the controller.
6863e41f4b71Sopenharmony_ci
6864e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6865e41f4b71Sopenharmony_ci
6866e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6867e41f4b71Sopenharmony_ci
6868e41f4b71Sopenharmony_ci**Parameters**
6869e41f4b71Sopenharmony_ci
6870e41f4b71Sopenharmony_ci| Name     | Type                                                   | Mandatory | Description                                                  |
6871e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6872e41f4b71Sopenharmony_ci| type     | string                                                 | Yes       | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes. |
6873e41f4b71Sopenharmony_ci| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | Yes       | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist. |
6874e41f4b71Sopenharmony_ci
6875e41f4b71Sopenharmony_ci**Error codes**
6876e41f4b71Sopenharmony_ci
6877e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6878e41f4b71Sopenharmony_ci
6879e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6880e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6881e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6882e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6883e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6884e41f4b71Sopenharmony_ci
6885e41f4b71Sopenharmony_ci**Example**
6886e41f4b71Sopenharmony_ci
6887e41f4b71Sopenharmony_ci```ts
6888e41f4b71Sopenharmony_ciavsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
6889e41f4b71Sopenharmony_ci  console.info(`OnQueueItemsChange, items length is ${items.length}`);
6890e41f4b71Sopenharmony_ci});
6891e41f4b71Sopenharmony_ci```
6892e41f4b71Sopenharmony_ci
6893e41f4b71Sopenharmony_ci### off('queueItemsChange')<sup>10+</sup>
6894e41f4b71Sopenharmony_ci
6895e41f4b71Sopenharmony_cioff(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
6896e41f4b71Sopenharmony_ci
6897e41f4b71Sopenharmony_ciUnsubscribes from playback item change events. This API is called by the controller.
6898e41f4b71Sopenharmony_ci
6899e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6900e41f4b71Sopenharmony_ci
6901e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6902e41f4b71Sopenharmony_ci
6903e41f4b71Sopenharmony_ci**Parameters**
6904e41f4b71Sopenharmony_ci
6905e41f4b71Sopenharmony_ci| Name     | Type                                                   | Mandatory | Description                                                  |
6906e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
6907e41f4b71Sopenharmony_ci| type     | string                                                 | Yes       | Event type, which is **'queueItemsChange'** in this case.    |
6908e41f4b71Sopenharmony_ci| 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. |
6909e41f4b71Sopenharmony_ci
6910e41f4b71Sopenharmony_ci**Error codes**
6911e41f4b71Sopenharmony_ci
6912e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6913e41f4b71Sopenharmony_ci
6914e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6915e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6916e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6917e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6918e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6919e41f4b71Sopenharmony_ci
6920e41f4b71Sopenharmony_ci**Example**
6921e41f4b71Sopenharmony_ci
6922e41f4b71Sopenharmony_ci```ts
6923e41f4b71Sopenharmony_ciavsessionController.off('queueItemsChange');
6924e41f4b71Sopenharmony_ci```
6925e41f4b71Sopenharmony_ci
6926e41f4b71Sopenharmony_ci### on('queueTitleChange')<sup>10+</sup>
6927e41f4b71Sopenharmony_ci
6928e41f4b71Sopenharmony_cion(type: 'queueTitleChange', callback: (title: string) => void): void
6929e41f4b71Sopenharmony_ci
6930e41f4b71Sopenharmony_ciSubscribes to playlist name change events. This API is called by the controller.
6931e41f4b71Sopenharmony_ci
6932e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6933e41f4b71Sopenharmony_ci
6934e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6935e41f4b71Sopenharmony_ci
6936e41f4b71Sopenharmony_ci**Parameters**
6937e41f4b71Sopenharmony_ci
6938e41f4b71Sopenharmony_ci| Name     | Type                    | Mandatory | Description                                                  |
6939e41f4b71Sopenharmony_ci| -------- | ----------------------- | --------- | ------------------------------------------------------------ |
6940e41f4b71Sopenharmony_ci| type     | string                  | Yes       | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes. |
6941e41f4b71Sopenharmony_ci| callback | (title: string) => void | Yes       | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name. |
6942e41f4b71Sopenharmony_ci
6943e41f4b71Sopenharmony_ci**Error codes**
6944e41f4b71Sopenharmony_ci
6945e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6946e41f4b71Sopenharmony_ci
6947e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6948e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6949e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6950e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6951e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6952e41f4b71Sopenharmony_ci
6953e41f4b71Sopenharmony_ci**Example**
6954e41f4b71Sopenharmony_ci
6955e41f4b71Sopenharmony_ci```ts
6956e41f4b71Sopenharmony_ciavsessionController.on('queueTitleChange', (title: string) => {
6957e41f4b71Sopenharmony_ci  console.info(`queueTitleChange, title is ${title}`);
6958e41f4b71Sopenharmony_ci});
6959e41f4b71Sopenharmony_ci```
6960e41f4b71Sopenharmony_ci
6961e41f4b71Sopenharmony_ci### off('queueTitleChange')<sup>10+</sup>
6962e41f4b71Sopenharmony_ci
6963e41f4b71Sopenharmony_cioff(type: 'queueTitleChange', callback?: (title: string) => void): void
6964e41f4b71Sopenharmony_ci
6965e41f4b71Sopenharmony_ciUnsubscribes from playlist name change events. This API is called by the controller.
6966e41f4b71Sopenharmony_ci
6967e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6968e41f4b71Sopenharmony_ci
6969e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
6970e41f4b71Sopenharmony_ci
6971e41f4b71Sopenharmony_ci**Parameters**
6972e41f4b71Sopenharmony_ci
6973e41f4b71Sopenharmony_ci| Name     | Type                    | Mandatory | Description                                                  |
6974e41f4b71Sopenharmony_ci| -------- | ----------------------- | --------- | ------------------------------------------------------------ |
6975e41f4b71Sopenharmony_ci| type     | string                  | Yes       | Event type, which is **'queueTitleChange'** in this case.    |
6976e41f4b71Sopenharmony_ci| 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. |
6977e41f4b71Sopenharmony_ci
6978e41f4b71Sopenharmony_ci**Error codes**
6979e41f4b71Sopenharmony_ci
6980e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6981e41f4b71Sopenharmony_ci
6982e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
6983e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
6984e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6985e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
6986e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
6987e41f4b71Sopenharmony_ci
6988e41f4b71Sopenharmony_ci**Example**
6989e41f4b71Sopenharmony_ci
6990e41f4b71Sopenharmony_ci```ts
6991e41f4b71Sopenharmony_ciavsessionController.off('queueTitleChange');
6992e41f4b71Sopenharmony_ci```
6993e41f4b71Sopenharmony_ci
6994e41f4b71Sopenharmony_ci### on('extrasChange')<sup>10+</sup>
6995e41f4b71Sopenharmony_ci
6996e41f4b71Sopenharmony_cion(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void
6997e41f4b71Sopenharmony_ci
6998e41f4b71Sopenharmony_ciSubscribes to custom media packet change events. This API is called by the controller.
6999e41f4b71Sopenharmony_ci
7000e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7001e41f4b71Sopenharmony_ci
7002e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7003e41f4b71Sopenharmony_ci
7004e41f4b71Sopenharmony_ci**Parameters**
7005e41f4b71Sopenharmony_ci
7006e41f4b71Sopenharmony_ci| Name     | Type                                     | Mandatory | Description                                                  |
7007e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ |
7008e41f4b71Sopenharmony_ci| type     | string                                   | Yes       | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet. |
7009e41f4b71Sopenharmony_ci| 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**. |
7010e41f4b71Sopenharmony_ci
7011e41f4b71Sopenharmony_ci**Error codes**
7012e41f4b71Sopenharmony_ci
7013e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7014e41f4b71Sopenharmony_ci
7015e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
7016e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
7017e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7018e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
7019e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
7020e41f4b71Sopenharmony_ci
7021e41f4b71Sopenharmony_ci**Example**
7022e41f4b71Sopenharmony_ci
7023e41f4b71Sopenharmony_ci```ts
7024e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7025e41f4b71Sopenharmony_ci
7026e41f4b71Sopenharmony_cilet avSessionController: avSession.AVSessionController | undefined = undefined;
7027e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined;
7028e41f4b71Sopenharmony_cilet tag = "createNewSession";
7029e41f4b71Sopenharmony_cilet context: Context = getContext(this);
7030e41f4b71Sopenharmony_ci
7031e41f4b71Sopenharmony_ciavSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
7032e41f4b71Sopenharmony_ci  if (err) {
7033e41f4b71Sopenharmony_ci    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
7034e41f4b71Sopenharmony_ci  } else {
7035e41f4b71Sopenharmony_ci    currentAVSession = data;
7036e41f4b71Sopenharmony_ci  }
7037e41f4b71Sopenharmony_ci});
7038e41f4b71Sopenharmony_ciif (currentAVSession !== undefined) {
7039e41f4b71Sopenharmony_ci  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
7040e41f4b71Sopenharmony_ci    avSessionController = controller;
7041e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
7042e41f4b71Sopenharmony_ci    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
7043e41f4b71Sopenharmony_ci  });
7044e41f4b71Sopenharmony_ci}
7045e41f4b71Sopenharmony_ci
7046e41f4b71Sopenharmony_ciif (avSessionController !== undefined) {
7047e41f4b71Sopenharmony_ci  (avSessionController as avSession.AVSessionController).on('extrasChange', (extras) => {
7048e41f4b71Sopenharmony_ci    console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
7049e41f4b71Sopenharmony_ci  });
7050e41f4b71Sopenharmony_ci}
7051e41f4b71Sopenharmony_ci```
7052e41f4b71Sopenharmony_ci
7053e41f4b71Sopenharmony_ci### off('extrasChange')<sup>10+</sup>
7054e41f4b71Sopenharmony_ci
7055e41f4b71Sopenharmony_cioff(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void
7056e41f4b71Sopenharmony_ci
7057e41f4b71Sopenharmony_ciUnsubscribes from custom media packet change events. This API is called by the controller.
7058e41f4b71Sopenharmony_ci
7059e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7060e41f4b71Sopenharmony_ci
7061e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7062e41f4b71Sopenharmony_ci
7063e41f4b71Sopenharmony_ci**Parameters**
7064e41f4b71Sopenharmony_ci
7065e41f4b71Sopenharmony_ci| Name     | Type                             | Mandatory | Description                                                  |
7066e41f4b71Sopenharmony_ci| -------- | -------------------------------- | --------- | ------------------------------------------------------------ |
7067e41f4b71Sopenharmony_ci| type     | string                           | Yes       | Event type, which is **'extrasChange'** in this case.        |
7068e41f4b71Sopenharmony_ci| 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. |
7069e41f4b71Sopenharmony_ci
7070e41f4b71Sopenharmony_ci**Error codes**
7071e41f4b71Sopenharmony_ci
7072e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7073e41f4b71Sopenharmony_ci
7074e41f4b71Sopenharmony_ci| ID      | Error Message                                                |
7075e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
7076e41f4b71Sopenharmony_ci| 401     | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7077e41f4b71Sopenharmony_ci| 6600101 | Session service exception.                                   |
7078e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist.                       |
7079e41f4b71Sopenharmony_ci
7080e41f4b71Sopenharmony_ci**Example**
7081e41f4b71Sopenharmony_ci
7082e41f4b71Sopenharmony_ci```ts
7083e41f4b71Sopenharmony_ciavsessionController.off('extrasChange');
7084e41f4b71Sopenharmony_ci```
7085e41f4b71Sopenharmony_ci
7086e41f4b71Sopenharmony_ci### getAVPlaybackStateSync<sup>10+</sup>
7087e41f4b71Sopenharmony_ci
7088e41f4b71Sopenharmony_cigetAVPlaybackStateSync(): AVPlaybackState;
7089e41f4b71Sopenharmony_ci
7090e41f4b71Sopenharmony_ciObtains the playback state of this session. This API returns the result synchronously.
7091e41f4b71Sopenharmony_ci
7092e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7093e41f4b71Sopenharmony_ci
7094e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7095e41f4b71Sopenharmony_ci
7096e41f4b71Sopenharmony_ci**Return value**
7097e41f4b71Sopenharmony_ci
7098e41f4b71Sopenharmony_ci| Type                                  | Description                    |
7099e41f4b71Sopenharmony_ci| ------------------------------------- | ------------------------------ |
7100e41f4b71Sopenharmony_ci| [AVPlaybackState](#avplaybackstate10) | Playback state of the session. |
7101e41f4b71Sopenharmony_ci
7102e41f4b71Sopenharmony_ci**Error codes**
7103e41f4b71Sopenharmony_ci
7104e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7105e41f4b71Sopenharmony_ci
7106e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7107e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7108e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7109e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7110e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7111e41f4b71Sopenharmony_ci
7112e41f4b71Sopenharmony_ci**Example**
7113e41f4b71Sopenharmony_ci
7114e41f4b71Sopenharmony_ci```ts
7115e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7116e41f4b71Sopenharmony_ci
7117e41f4b71Sopenharmony_citry {
7118e41f4b71Sopenharmony_ci  let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync();
7119e41f4b71Sopenharmony_ci} catch (err) {
7120e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7121e41f4b71Sopenharmony_ci  console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`);
7122e41f4b71Sopenharmony_ci}
7123e41f4b71Sopenharmony_ci```
7124e41f4b71Sopenharmony_ci
7125e41f4b71Sopenharmony_ci### getAVMetadataSync<sup>10+</sup>
7126e41f4b71Sopenharmony_ci
7127e41f4b71Sopenharmony_cigetAVMetadataSync(): AVMetadata
7128e41f4b71Sopenharmony_ci
7129e41f4b71Sopenharmony_ciObtains the session metadata. This API returns the result synchronously.
7130e41f4b71Sopenharmony_ci
7131e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7132e41f4b71Sopenharmony_ci
7133e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7134e41f4b71Sopenharmony_ci
7135e41f4b71Sopenharmony_ci**Return value**
7136e41f4b71Sopenharmony_ci
7137e41f4b71Sopenharmony_ci| Type                        | Description       |
7138e41f4b71Sopenharmony_ci| --------------------------- | ----------------- |
7139e41f4b71Sopenharmony_ci| [AVMetadata](#avmetadata10) | Session metadata. |
7140e41f4b71Sopenharmony_ci
7141e41f4b71Sopenharmony_ci**Error codes**
7142e41f4b71Sopenharmony_ci
7143e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7144e41f4b71Sopenharmony_ci
7145e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7146e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7147e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7148e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7149e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7150e41f4b71Sopenharmony_ci
7151e41f4b71Sopenharmony_ci**Example**
7152e41f4b71Sopenharmony_ci```ts
7153e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7154e41f4b71Sopenharmony_ci
7155e41f4b71Sopenharmony_citry {
7156e41f4b71Sopenharmony_ci  let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync();
7157e41f4b71Sopenharmony_ci} catch (err) {
7158e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7159e41f4b71Sopenharmony_ci  console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`);
7160e41f4b71Sopenharmony_ci}
7161e41f4b71Sopenharmony_ci```
7162e41f4b71Sopenharmony_ci
7163e41f4b71Sopenharmony_ci### getAVCallState<sup>11+</sup>
7164e41f4b71Sopenharmony_ci
7165e41f4b71Sopenharmony_cigetAVCallState(): Promise\<AVCallState>
7166e41f4b71Sopenharmony_ci
7167e41f4b71Sopenharmony_ciObtains the call state. This API uses a promise to return the result.
7168e41f4b71Sopenharmony_ci
7169e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7170e41f4b71Sopenharmony_ci
7171e41f4b71Sopenharmony_ci**Return value**
7172e41f4b71Sopenharmony_ci
7173e41f4b71Sopenharmony_ci| Type                                    | Description                                     |
7174e41f4b71Sopenharmony_ci| --------------------------------------- | ----------------------------------------------- |
7175e41f4b71Sopenharmony_ci| Promise<[AVCallState](#avcallstate11)\> | Promise used to return the call state obtained. |
7176e41f4b71Sopenharmony_ci
7177e41f4b71Sopenharmony_ci**Error codes**
7178e41f4b71Sopenharmony_ci
7179e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7180e41f4b71Sopenharmony_ci
7181e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7182e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7183e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7184e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7185e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7186e41f4b71Sopenharmony_ci
7187e41f4b71Sopenharmony_ci**Example**
7188e41f4b71Sopenharmony_ci
7189e41f4b71Sopenharmony_ci```ts
7190e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7191e41f4b71Sopenharmony_ci
7192e41f4b71Sopenharmony_ciavsessionController.getAVCallState().then((callstate: avSession.AVCallState) => {
7193e41f4b71Sopenharmony_ci  console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7194e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7195e41f4b71Sopenharmony_ci  console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7196e41f4b71Sopenharmony_ci});
7197e41f4b71Sopenharmony_ci```
7198e41f4b71Sopenharmony_ci
7199e41f4b71Sopenharmony_ci### getAVCallState<sup>11+</sup>
7200e41f4b71Sopenharmony_ci
7201e41f4b71Sopenharmony_cigetAVCallState(callback: AsyncCallback\<AVCallState>): void
7202e41f4b71Sopenharmony_ci
7203e41f4b71Sopenharmony_ciObtains the call state. This API uses an asynchronous callback to return the result.
7204e41f4b71Sopenharmony_ci
7205e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7206e41f4b71Sopenharmony_ci
7207e41f4b71Sopenharmony_ci**Parameters**
7208e41f4b71Sopenharmony_ci
7209e41f4b71Sopenharmony_ci| Name     | Type                                          | Mandatory | Description                                      |
7210e41f4b71Sopenharmony_ci| -------- | --------------------------------------------- | --------- | ------------------------------------------------ |
7211e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | Yes       | Callback used to return the call state obtained. |
7212e41f4b71Sopenharmony_ci
7213e41f4b71Sopenharmony_ci**Error codes**
7214e41f4b71Sopenharmony_ci
7215e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7216e41f4b71Sopenharmony_ci
7217e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7218e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7219e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7220e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7221e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7222e41f4b71Sopenharmony_ci
7223e41f4b71Sopenharmony_ci**Example**
7224e41f4b71Sopenharmony_ci
7225e41f4b71Sopenharmony_ci```ts
7226e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7227e41f4b71Sopenharmony_ci
7228e41f4b71Sopenharmony_ciavsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => {
7229e41f4b71Sopenharmony_ci  if (err) {
7230e41f4b71Sopenharmony_ci    console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7231e41f4b71Sopenharmony_ci  } else {
7232e41f4b71Sopenharmony_ci    console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7233e41f4b71Sopenharmony_ci  }
7234e41f4b71Sopenharmony_ci});
7235e41f4b71Sopenharmony_ci```
7236e41f4b71Sopenharmony_ci
7237e41f4b71Sopenharmony_ci### getCallMetadata<sup>11+</sup>
7238e41f4b71Sopenharmony_ci
7239e41f4b71Sopenharmony_cigetCallMetadata(): Promise\<CallMetadata>
7240e41f4b71Sopenharmony_ci
7241e41f4b71Sopenharmony_ciObtains the call metadata. This API uses a promise to return the result.
7242e41f4b71Sopenharmony_ci
7243e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7244e41f4b71Sopenharmony_ci
7245e41f4b71Sopenharmony_ci**Return value**
7246e41f4b71Sopenharmony_ci
7247e41f4b71Sopenharmony_ci| Type                                      | Description                                   |
7248e41f4b71Sopenharmony_ci| ----------------------------------------- | --------------------------------------------- |
7249e41f4b71Sopenharmony_ci| Promise<[CallMetadata](#callmetadata11)\> | Promise used to return the metadata obtained. |
7250e41f4b71Sopenharmony_ci
7251e41f4b71Sopenharmony_ci**Error codes**
7252e41f4b71Sopenharmony_ci
7253e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7254e41f4b71Sopenharmony_ci
7255e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7256e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7257e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7258e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7259e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7260e41f4b71Sopenharmony_ci
7261e41f4b71Sopenharmony_ci**Example**
7262e41f4b71Sopenharmony_ci
7263e41f4b71Sopenharmony_ci```ts
7264e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7265e41f4b71Sopenharmony_ci
7266e41f4b71Sopenharmony_ciavsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => {
7267e41f4b71Sopenharmony_ci  console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
7268e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
7269e41f4b71Sopenharmony_ci  console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
7270e41f4b71Sopenharmony_ci});
7271e41f4b71Sopenharmony_ci```
7272e41f4b71Sopenharmony_ci
7273e41f4b71Sopenharmony_ci### getCallMetadata<sup>11+</sup>
7274e41f4b71Sopenharmony_ci
7275e41f4b71Sopenharmony_cigetCallMetadata(callback: AsyncCallback\<CallMetadata>): void
7276e41f4b71Sopenharmony_ci
7277e41f4b71Sopenharmony_ciObtains the call metadata. This API uses an asynchronous callback to return the result.
7278e41f4b71Sopenharmony_ci
7279e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7280e41f4b71Sopenharmony_ci
7281e41f4b71Sopenharmony_ci**Parameters**
7282e41f4b71Sopenharmony_ci
7283e41f4b71Sopenharmony_ci| Name     | Type                                            | Mandatory | Description                                    |
7284e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | --------- | ---------------------------------------------- |
7285e41f4b71Sopenharmony_ci| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | Yes       | Callback used to return the metadata obtained. |
7286e41f4b71Sopenharmony_ci
7287e41f4b71Sopenharmony_ci**Error codes**
7288e41f4b71Sopenharmony_ci
7289e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7290e41f4b71Sopenharmony_ci
7291e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7292e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7293e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7294e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7295e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7296e41f4b71Sopenharmony_ci
7297e41f4b71Sopenharmony_ci**Example**
7298e41f4b71Sopenharmony_ci
7299e41f4b71Sopenharmony_ci```ts
7300e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7301e41f4b71Sopenharmony_ci
7302e41f4b71Sopenharmony_ciavsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => {
7303e41f4b71Sopenharmony_ci  if (err) {
7304e41f4b71Sopenharmony_ci    console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
7305e41f4b71Sopenharmony_ci  } else {
7306e41f4b71Sopenharmony_ci    console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
7307e41f4b71Sopenharmony_ci  }
7308e41f4b71Sopenharmony_ci});
7309e41f4b71Sopenharmony_ci```
7310e41f4b71Sopenharmony_ci
7311e41f4b71Sopenharmony_ci### getAVQueueTitleSync<sup>10+</sup>
7312e41f4b71Sopenharmony_ci
7313e41f4b71Sopenharmony_cigetAVQueueTitleSync(): string
7314e41f4b71Sopenharmony_ci
7315e41f4b71Sopenharmony_ciObtains the name of the playlist of this session. This API returns the result synchronously.
7316e41f4b71Sopenharmony_ci
7317e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7318e41f4b71Sopenharmony_ci
7319e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7320e41f4b71Sopenharmony_ci
7321e41f4b71Sopenharmony_ci**Return value**
7322e41f4b71Sopenharmony_ci
7323e41f4b71Sopenharmony_ci| Type   | Description    |
7324e41f4b71Sopenharmony_ci| ------ | -------------- |
7325e41f4b71Sopenharmony_ci| string | Playlist name. |
7326e41f4b71Sopenharmony_ci
7327e41f4b71Sopenharmony_ci**Error codes**
7328e41f4b71Sopenharmony_ci
7329e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7330e41f4b71Sopenharmony_ci
7331e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7332e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7333e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7334e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7335e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7336e41f4b71Sopenharmony_ci
7337e41f4b71Sopenharmony_ci**Example**
7338e41f4b71Sopenharmony_ci
7339e41f4b71Sopenharmony_ci```ts
7340e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7341e41f4b71Sopenharmony_ci
7342e41f4b71Sopenharmony_citry {
7343e41f4b71Sopenharmony_ci  let currentQueueTitle: string = avsessionController.getAVQueueTitleSync();
7344e41f4b71Sopenharmony_ci} catch (err) {
7345e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7346e41f4b71Sopenharmony_ci  console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`);
7347e41f4b71Sopenharmony_ci}
7348e41f4b71Sopenharmony_ci```
7349e41f4b71Sopenharmony_ci
7350e41f4b71Sopenharmony_ci### getAVQueueItemsSync<sup>10+</sup>
7351e41f4b71Sopenharmony_ci
7352e41f4b71Sopenharmony_cigetAVQueueItemsSync(): Array\<AVQueueItem\>
7353e41f4b71Sopenharmony_ci
7354e41f4b71Sopenharmony_ciObtains the information related to the items in the playlist of this session. This API returns the result synchronously.
7355e41f4b71Sopenharmony_ci
7356e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7357e41f4b71Sopenharmony_ci
7358e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7359e41f4b71Sopenharmony_ci
7360e41f4b71Sopenharmony_ci**Return value**
7361e41f4b71Sopenharmony_ci
7362e41f4b71Sopenharmony_ci| Type                                  | Description         |
7363e41f4b71Sopenharmony_ci| ------------------------------------- | ------------------- |
7364e41f4b71Sopenharmony_ci| Array<[AVQueueItem](#avqueueitem10)\> | Items in the queue. |
7365e41f4b71Sopenharmony_ci
7366e41f4b71Sopenharmony_ci**Error codes**
7367e41f4b71Sopenharmony_ci
7368e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7369e41f4b71Sopenharmony_ci
7370e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7371e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7372e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7373e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7374e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7375e41f4b71Sopenharmony_ci
7376e41f4b71Sopenharmony_ci**Example**
7377e41f4b71Sopenharmony_ci
7378e41f4b71Sopenharmony_ci```ts
7379e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7380e41f4b71Sopenharmony_ci
7381e41f4b71Sopenharmony_citry {
7382e41f4b71Sopenharmony_ci  let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync();
7383e41f4b71Sopenharmony_ci} catch (err) {
7384e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7385e41f4b71Sopenharmony_ci  console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`);
7386e41f4b71Sopenharmony_ci}
7387e41f4b71Sopenharmony_ci```
7388e41f4b71Sopenharmony_ci
7389e41f4b71Sopenharmony_ci### getOutputDeviceSync<sup>10+</sup>
7390e41f4b71Sopenharmony_ci
7391e41f4b71Sopenharmony_cigetOutputDeviceSync(): OutputDeviceInfo
7392e41f4b71Sopenharmony_ci
7393e41f4b71Sopenharmony_ciObtains the output device information. This API returns the result synchronously.
7394e41f4b71Sopenharmony_ci
7395e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7396e41f4b71Sopenharmony_ci
7397e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7398e41f4b71Sopenharmony_ci
7399e41f4b71Sopenharmony_ci**Return value**
7400e41f4b71Sopenharmony_ci
7401e41f4b71Sopenharmony_ci| Type                                    | Description                          |
7402e41f4b71Sopenharmony_ci| --------------------------------------- | ------------------------------------ |
7403e41f4b71Sopenharmony_ci| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device. |
7404e41f4b71Sopenharmony_ci
7405e41f4b71Sopenharmony_ci**Error codes**
7406e41f4b71Sopenharmony_ci
7407e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7408e41f4b71Sopenharmony_ci
7409e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7410e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7411e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7412e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7413e41f4b71Sopenharmony_ci
7414e41f4b71Sopenharmony_ci**Example**
7415e41f4b71Sopenharmony_ci
7416e41f4b71Sopenharmony_ci```ts
7417e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7418e41f4b71Sopenharmony_ci
7419e41f4b71Sopenharmony_citry {
7420e41f4b71Sopenharmony_ci  let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync();
7421e41f4b71Sopenharmony_ci} catch (err) {
7422e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7423e41f4b71Sopenharmony_ci  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
7424e41f4b71Sopenharmony_ci}
7425e41f4b71Sopenharmony_ci```
7426e41f4b71Sopenharmony_ci
7427e41f4b71Sopenharmony_ci### isActiveSync<sup>10+</sup>
7428e41f4b71Sopenharmony_ci
7429e41f4b71Sopenharmony_ciisActiveSync(): boolean
7430e41f4b71Sopenharmony_ci
7431e41f4b71Sopenharmony_ciChecks whether the session is activated. This API returns the result synchronously.
7432e41f4b71Sopenharmony_ci
7433e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7434e41f4b71Sopenharmony_ci
7435e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7436e41f4b71Sopenharmony_ci
7437e41f4b71Sopenharmony_ci**Return value**
7438e41f4b71Sopenharmony_ci
7439e41f4b71Sopenharmony_ci| Type    | Description                                                  |
7440e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
7441e41f4b71Sopenharmony_ci| boolean | Returns **true** is returned if the session is activated; returns **false** otherwise. |
7442e41f4b71Sopenharmony_ci
7443e41f4b71Sopenharmony_ci**Error codes**
7444e41f4b71Sopenharmony_ci
7445e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7446e41f4b71Sopenharmony_ci
7447e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7448e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7449e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7450e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7451e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7452e41f4b71Sopenharmony_ci
7453e41f4b71Sopenharmony_ci**Example**
7454e41f4b71Sopenharmony_ci
7455e41f4b71Sopenharmony_ci```ts
7456e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7457e41f4b71Sopenharmony_ci
7458e41f4b71Sopenharmony_citry {
7459e41f4b71Sopenharmony_ci  let isActive: boolean = avsessionController.isActiveSync();
7460e41f4b71Sopenharmony_ci} catch (err) {
7461e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7462e41f4b71Sopenharmony_ci  console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`);
7463e41f4b71Sopenharmony_ci}
7464e41f4b71Sopenharmony_ci```
7465e41f4b71Sopenharmony_ci
7466e41f4b71Sopenharmony_ci### getValidCommandsSync<sup>10+</sup>
7467e41f4b71Sopenharmony_ci
7468e41f4b71Sopenharmony_cigetValidCommandsSync(): Array\<AVControlCommandType\>
7469e41f4b71Sopenharmony_ci
7470e41f4b71Sopenharmony_ciObtains valid commands supported by the session. This API returns the result synchronously.
7471e41f4b71Sopenharmony_ci
7472e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7473e41f4b71Sopenharmony_ci
7474e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7475e41f4b71Sopenharmony_ci
7476e41f4b71Sopenharmony_ci**Return value**
7477e41f4b71Sopenharmony_ci
7478e41f4b71Sopenharmony_ci| Type                                                    | Description              |
7479e41f4b71Sopenharmony_ci| ------------------------------------------------------- | ------------------------ |
7480e41f4b71Sopenharmony_ci| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | A set of valid commands. |
7481e41f4b71Sopenharmony_ci
7482e41f4b71Sopenharmony_ci**Error codes**
7483e41f4b71Sopenharmony_ci
7484e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7485e41f4b71Sopenharmony_ci
7486e41f4b71Sopenharmony_ci| ID      | Error Message                          |
7487e41f4b71Sopenharmony_ci| ------- | -------------------------------------- |
7488e41f4b71Sopenharmony_ci| 6600101 | Session service exception.             |
7489e41f4b71Sopenharmony_ci| 6600102 | The session does not exist.            |
7490e41f4b71Sopenharmony_ci| 6600103 | The session controller does not exist. |
7491e41f4b71Sopenharmony_ci
7492e41f4b71Sopenharmony_ci**Example**
7493e41f4b71Sopenharmony_ci
7494e41f4b71Sopenharmony_ci```ts
7495e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
7496e41f4b71Sopenharmony_ci
7497e41f4b71Sopenharmony_citry {
7498e41f4b71Sopenharmony_ci  let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync();
7499e41f4b71Sopenharmony_ci} catch (err) {
7500e41f4b71Sopenharmony_ci  let error = err as BusinessError;
7501e41f4b71Sopenharmony_ci  console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`);
7502e41f4b71Sopenharmony_ci}
7503e41f4b71Sopenharmony_ci```
7504e41f4b71Sopenharmony_ci
7505e41f4b71Sopenharmony_ci## AVControlCommandType<sup>10+</sup>
7506e41f4b71Sopenharmony_ci
7507e41f4b71Sopenharmony_citype AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
7508e41f4b71Sopenharmony_ci  'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute'
7509e41f4b71Sopenharmony_ci
7510e41f4b71Sopenharmony_ciEnumerates the commands that can be sent to a session.
7511e41f4b71Sopenharmony_ci
7512e41f4b71Sopenharmony_ciYou can use the union of the strings listed in the following table.
7513e41f4b71Sopenharmony_ci
7514e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7515e41f4b71Sopenharmony_ci
7516e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7517e41f4b71Sopenharmony_ci
7518e41f4b71Sopenharmony_ci| Type              | Description                                       |
7519e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------------------- |
7520e41f4b71Sopenharmony_ci| 'play'            | Play the media.                                   |
7521e41f4b71Sopenharmony_ci| 'pause'           | Pause the playback.                               |
7522e41f4b71Sopenharmony_ci| 'stop'            | Stop the playback.                                |
7523e41f4b71Sopenharmony_ci| 'playNext'        | Play the next media asset.                        |
7524e41f4b71Sopenharmony_ci| 'playPrevious'    | Play the previous media asset.                    |
7525e41f4b71Sopenharmony_ci| 'fastForward'     | Fast-forward.                                     |
7526e41f4b71Sopenharmony_ci| 'rewind'          | Rewind.                                           |
7527e41f4b71Sopenharmony_ci| 'seek'            | Seek to a playback position.                      |
7528e41f4b71Sopenharmony_ci| 'setSpeed'        | Set the playback speed.                           |
7529e41f4b71Sopenharmony_ci| 'setLoopMode'     | Set the loop mode.                                |
7530e41f4b71Sopenharmony_ci| 'toggleFavorite'  | Favorite the media asset.                         |
7531e41f4b71Sopenharmony_ci| 'playFromAssetId' | Play the media asset with the specified asset ID. |
7532e41f4b71Sopenharmony_ci| 'answer'          | Answer a call.                                    |
7533e41f4b71Sopenharmony_ci| 'hangUp'          | The call is disconnecting.                        |
7534e41f4b71Sopenharmony_ci| 'toggleCallMute'  | Set the mute status for a call.                   |
7535e41f4b71Sopenharmony_ci
7536e41f4b71Sopenharmony_ci## AVControlCommand<sup>10+</sup>
7537e41f4b71Sopenharmony_ci
7538e41f4b71Sopenharmony_ciDescribes the command that can be sent to the session.
7539e41f4b71Sopenharmony_ci
7540e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7541e41f4b71Sopenharmony_ci
7542e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7543e41f4b71Sopenharmony_ci
7544e41f4b71Sopenharmony_ci| Name      | Type                                                | Mandatory | Description                        |
7545e41f4b71Sopenharmony_ci| --------- | --------------------------------------------------- | --------- | ---------------------------------- |
7546e41f4b71Sopenharmony_ci| command   | [AVControlCommandType](#avcontrolcommandtype10)     | Yes       | Command.                           |
7547e41f4b71Sopenharmony_ci| parameter | [LoopMode](#loopmode10) &#124; string &#124; number | No        | Parameters carried in the command. |
7548e41f4b71Sopenharmony_ci
7549e41f4b71Sopenharmony_ci## AVSessionErrorCode<sup>10+</sup>
7550e41f4b71Sopenharmony_ci
7551e41f4b71Sopenharmony_ciEnumerates the error codes used in the media session.
7552e41f4b71Sopenharmony_ci
7553e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7554e41f4b71Sopenharmony_ci
7555e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7556e41f4b71Sopenharmony_ci
7557e41f4b71Sopenharmony_ci| Name                                 | Value   | Description                               |
7558e41f4b71Sopenharmony_ci| ------------------------------------ | ------- | ----------------------------------------- |
7559e41f4b71Sopenharmony_ci| ERR_CODE_SERVICE_EXCEPTION           | 6600101 | Session service exception.                |
7560e41f4b71Sopenharmony_ci| ERR_CODE_SESSION_NOT_EXIST           | 6600102 | The session does not exist.               |
7561e41f4b71Sopenharmony_ci| ERR_CODE_CONTROLLER_NOT_EXIST        | 6600103 | The session controller does not exist.    |
7562e41f4b71Sopenharmony_ci| ERR_CODE_REMOTE_CONNECTION_ERR       | 6600104 | The remote session  connection failed.    |
7563e41f4b71Sopenharmony_ci| ERR_CODE_COMMAND_INVALID             | 6600105 | Invalid session command.                  |
7564e41f4b71Sopenharmony_ci| ERR_CODE_SESSION_INACTIVE            | 6600106 | The session is not activated.             |
7565e41f4b71Sopenharmony_ci| ERR_CODE_MESSAGE_OVERLOAD            | 6600107 | Too many commands or events.              |
7566e41f4b71Sopenharmony_ci| ERR_CODE_DEVICE_CONNECTION_FAILED    | 6600108 | Device connection failed.                 |
7567e41f4b71Sopenharmony_ci| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST | 6600109 | The remote connection is not established. |
7568e41f4b71Sopenharmony_ci
7569e41f4b71Sopenharmony_ci## SkipIntervals<sup>11+</sup>
7570e41f4b71Sopenharmony_ci
7571e41f4b71Sopenharmony_ciEnumerates the fast-forward or rewind intervals supported by the media session.
7572e41f4b71Sopenharmony_ci
7573e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core
7574e41f4b71Sopenharmony_ci
7575e41f4b71Sopenharmony_ci| Name       | Value | Description             |
7576e41f4b71Sopenharmony_ci| ---------- | ----- | ----------------------- |
7577e41f4b71Sopenharmony_ci| SECONDS_10 | 10    | The time is 10 seconds. |
7578e41f4b71Sopenharmony_ci| SECONDS_15 | 15    | The time is 15 seconds. |
7579e41f4b71Sopenharmony_ci| SECONDS_30 | 30    | The time is 30 seconds. |