Through the AV session controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
import { avSession } from '@kit.AVSessionKit';
import { BusinessError } from '@kit.BasicServicesKit'; Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| sessionId10+ | string | Yes | No | Unique session ID of the AVSessionController object. |
Example
// Index.ets
import { avSession } from '@kit.AVSessionKit';
@Entry
@Component
struct Index {
private tag: string = "createNewSession";
private sessionId: string = "";
private avsessionController?: avSession.AVSessionController;
private currentAVSession?: avSession.AVSession;
aboutToAppear(): void {
avSession.createAVSession(this.getUIContext().getHostContext(), this.tag, "audio").then(async (data: avSession.AVSession) => {
this.currentAVSession = data;
this.sessionId = this.currentAVSession.sessionId;
this.avsessionController = await this.currentAVSession.getController();
console.info(`Succeeded in creating AV session, sessionId: ${this.sessionId}`);
});
}
build() {
Column() {
Text('AVSession Demo')
.fontSize(20)
.margin(10)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
} getAVPlaybackState(callback: AsyncCallback<AVPlaybackState>): void
Obtains the remote playback state. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<AVPlaybackState> | Yes | Callback used to return the remote playback state. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
if (err) {
console.error(`Failed to get AV playback state, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in getting AV playback state.');
}); getAVPlaybackState(): Promise<AVPlaybackState>
Obtains the remote playback state. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<AVPlaybackState> | Promise used to return the remote playback status. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
console.info('Succeeded in getting AV playback state.');
}); getAVMetadata(): Promise<AVMetadata>
Obtains the session metadata. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<AVMetadata> | Promise used to return the metadata obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVMetadata().then((metadata: avSession.AVMetadata) => {
console.info(`Succeeded in getting AV metadata, assetId: ${metadata.assetId}`);
}); getAVMetadata(callback: AsyncCallback<AVMetadata>): void
Obtains the session metadata. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<AVMetadata> | Yes | Callback used to return the metadata obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
if (err) {
console.error(`Failed to get AV metadata, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting AV metadata, assetId: ${metadata.assetId}`);
}); getAVQueueTitle(): Promise<string>
Obtains the name of the playlist. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the playlist name. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVQueueTitle().then((title: string) => {
console.info(`Succeeded in getting AV queue title: ${title}`);
}); getAVQueueTitle(callback: AsyncCallback<string>): void
Obtains the name of the playlist. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<string> | Yes | Callback used to return the playlist name. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVQueueTitle((err: BusinessError, title: string) => {
if (err) {
console.error(`Failed to get AV queue title, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting AV queue title: ${title}`);
}); getAVQueueItems(): Promise<Array<AVQueueItem>>
Obtains the information related to the items in the queue. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<Array<AVQueueItem>> | Promise used to return the items in the queue. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
console.info(`Succeeded in getting AV queue items, length: ${items.length}`);
}); getAVQueueItems(callback: AsyncCallback<Array<AVQueueItem>>): void
Obtains the information related to the items in the queue. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<AVQueueItem>> | Yes | Callback used to return the items in the playlist. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
if (err) {
console.error(`Failed to get AV queue items, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting AV queue items, length: ${items.length}`);
}); skipToQueueItem(itemId: number): Promise<void>
Sends the ID of an item in the playlist to the session for processing. The session can play the song. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| itemId | number | Yes | ID of an item in the playlist. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let queueItemId = 0;
avcontroller.skipToQueueItem(queueItemId).then(() => {
console.info('Succeeded in skipping to queue item.');
}); skipToQueueItem(itemId: number, callback: AsyncCallback<void>): void
Sends the ID of an item in the playlist to the session for processing. The session can play the song. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| itemId | number | Yes | ID of an item in the playlist. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the setting is successful, err is undefined; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let queueItemId = 0;
avcontroller.skipToQueueItem(queueItemId, (err: BusinessError) => {
if (err) {
console.error(`Failed to skip to queue item, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in skipping to queue item.');
}); getOutputDevice(): Promise<OutputDeviceInfo>
Obtains the output device information. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<OutputDeviceInfo> | Promise used to return the information obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 600101 | Session service exception. |
| 600103 | The session controller does not exist. |
Example
avcontroller.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
console.info('Succeeded in getting output device.');
}); getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void
Obtains the output device information. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<OutputDeviceInfo> | Yes | Callback used to return the information obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 600101 | Session service exception. |
| 600103 | The session controller does not exist. |
Example
avcontroller.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
if (err) {
console.error(`Failed to get output device, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in getting output device.');
}); sendAVKeyEvent(event: KeyEvent): Promise<void>
Sends a key event to the session corresponding to this controller. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| event | KeyEvent | Yes | Key event. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 600101 | Session service exception. |
| 600102 | The session does not exist. |
| 600103 | The session controller does not exist. |
| 600105 | Invalid session command. |
| 600106 | The session is not activated. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned. |
Example
import { Key, KeyEvent } from '@kit.InputKit';
let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
let 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};
avcontroller.sendAVKeyEvent(event).then(() => {
console.info('Succeeded in sending AV key event.');
}); sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback<void>): void
Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| event | KeyEvent | Yes | Key event. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the event is sent, err is undefined; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 600101 | Session service exception. |
| 600102 | The session does not exist. |
| 600103 | The session controller does not exist. |
| 600105 | Invalid session command. |
| 600106 | The session is not activated. |
Example
import { Key, KeyEvent } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
let 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};
avcontroller.sendAVKeyEvent(event, (err: BusinessError) => {
if (err) {
console.error(`Failed to send AV key event, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in sending AV key event.');
}); getLaunchAbility(): Promise<WantAgent>
Obtains the WantAgent object saved by the application in the session. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<WantAgent> | Promise used to return the object saved by calling setLaunchAbility. The object includes the application property, such as the bundle name, ability name, and device ID. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
import { WantAgent } from '@kit.AbilityKit';
avcontroller.getLaunchAbility().then((agent: WantAgent) => {
console.info(`Succeeded in getting launch ability: ${agent}`);
}); getLaunchAbility(callback: AsyncCallback<WantAgent>): void
Obtains the WantAgent object saved by the application in the session. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<WantAgent> | Yes | Callback used to return the object saved by calling setLaunchAbility. The object includes the application property, such as the bundle name, ability name, and device ID. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
import { WantAgent } from '@kit.AbilityKit';
avcontroller.getLaunchAbility((err: BusinessError, agent: WantAgent) => {
if (err) {
console.error(`Failed to get launch ability, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting launch ability: ${agent}`);
}); getRealPlaybackPositionSync(): number
Obtains the current playback position. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| number | Playback position, in milliseconds. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
let time: number = avcontroller.getRealPlaybackPositionSync();
isActive(): Promise<boolean>
Checks whether the session is activated. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result indicating whether the session is activated. true if activated, false otherwise. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.isActive().then((isActive: boolean) => {
console.info(`Succeeded in checking active state: ${isActive}`);
}); isActive(callback: AsyncCallback<boolean>): void
Checks whether the session is activated. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<boolean> | Yes | Callback used to return whether the session is activated. true if activated, false otherwise. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.isActive((err: BusinessError, isActive: boolean) => {
if (err) {
console.error(`Failed to check active state, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in checking active state: ${isActive}`);
}); destroy(): Promise<void>
Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.destroy().then(() => {
console.info('Succeeded in destroying.');
}); destroy(callback: AsyncCallback<void>): void
Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the controller is destroyed, err is undefined; otherwise, err is an error object. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.destroy((err: BusinessError) => {
if (err) {
console.error(`Failed to destroy controller, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in destroying.');
}); getValidCommands(): Promise<Array<AVControlCommandType>>
Obtains valid commands supported by the session. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<Array<AVControlCommandType>> | Promise used to return a set of valid commands. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => {
console.info(`Succeeded in getting valid commands, size: ${validCommands.length}`);
}); getValidCommands(callback: AsyncCallback<Array<AVControlCommandType>>): void
Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<AVControlCommandType>> | Yes | Callback used to return a set of valid commands. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
if (err) {
console.error(`Failed to get valid commands, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting valid commands, size: ${validCommands.length}`);
}); sendControlCommand(command: AVControlCommand): Promise<void>
Sends a control command to the session through the controller. This API uses a promise to return the result.
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'), on('pause'), and the like.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| command | AVControlCommand | Yes | Command to send. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
| 6600106 | The session is not activated. |
| 6600107 | Too many commands or events. |
Example
let avCommand: avSession.AVControlCommand = {command:'play'};
avcontroller.sendControlCommand(avCommand).then(() => {
console.info('Succeeded in sending control command.');
}); sendControlCommand(command: AVControlCommand, callback: AsyncCallback<void>): void
Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
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'), on('pause'), and the like.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| command | AVControlCommand | Yes | Command to send. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the command is sent, err is undefined; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
| 6600106 | The session is not activated. |
| 6600107 | Too many commands or events. |
Example
let avCommand: avSession.AVControlCommand = {command:'play'};
avcontroller.sendControlCommand(avCommand, (err: BusinessError) => {
if (err) {
console.error(`Failed to send control command, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in sending control command.');
}); sendCommonCommand(command: string, args: {[key: string]: Object}): Promise<void>
Sends a custom control command to the session through the controller. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| command | string | Yes | Name of the custom control command. |
| args | {[key: string]: Object} | Yes | Parameters in key-value pair format carried in the custom control command. |
The args parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see @ohos.app.ability.Want (Want).
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
| 6600106 | The session is not activated. |
| 6600107 | Too many commands or events. |
Example
let commandName = "my_command";
avcontroller.sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
console.info('Succeeded in sending common command.');
}); sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback<void>): void
Sends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| command | string | Yes | Name of the custom control command. |
| args | {[key: string]: Object} | Yes | Parameters in key-value pair format carried in the custom control command. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the command is sent, err is undefined; otherwise, err is an error object. |
The args parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see @ohos.app.ability.Want (Want).
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
| 6600106 | The session is not activated. |
| 6600107 | Too many commands or events. |
Example
let commandName = "my_command";
avcontroller.sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
if (err) {
console.error(`Failed to send common command, code: ${err.code}, message: ${err.message}`);
return;
}
console.info('Succeeded in sending common command.');
}) sendCustomData(data: Record<string, Object>): Promise<void>
Sends custom data to the remote device. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.Multimedia.AVSession.AVCast
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| data | Record<string, Object> | Yes | Custom data filled by the application. Only objects with the key 'customData' and of the type string are parsed on the server. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
// Index.ets
import { avSession } from '@kit.AVSessionKit';
@Entry
@Component
struct Index {
private tag: string = "createNewSession";
private sessionId: string = "";
private controller: avSession.AVSessionController | undefined = undefined;
private currentAVSession?: avSession.AVSession;
aboutToAppear(): void {
avSession.createAVSession(this.getUIContext().getHostContext(), this.tag, "audio")
.then(async (data: avSession.AVSession) => {
this.currentAVSession = data;
this.sessionId = this.currentAVSession.sessionId;
this.controller = await this.currentAVSession.getController();
console.info(`Succeeded in creating AV session, sessionId: ${this.sessionId}`);
(this.controller as avSession.AVSessionController).sendCustomData({ customData: "This is my data" });
});
}
build() {
Column() {
Text('AVSession Demo')
.fontSize(20)
.margin(10)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
} getExtras(): Promise<{[key: string]: Object}>
Obtains the custom media packet set by the provider. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<{[key: string]: Object}> | Promise used to return the custom media packet. The content of the packet is the same as that set in setExtras. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
| 6600107 | Too many commands or events. |
Example
// Index.ets
import { avSession } from '@kit.AVSessionKit';
@Entry
@Component
struct Index {
private tag: string = "createNewSession";
private sessionId: string = "";
private controller: avSession.AVSessionController | undefined = undefined;
private currentAVSession?: avSession.AVSession;
aboutToAppear(): void {
avSession.createAVSession(this.getUIContext().getHostContext(), this.tag, "audio")
.then(async (data: avSession.AVSession) => {
this.currentAVSession = data;
this.sessionId = this.currentAVSession.sessionId;
this.controller = await this.currentAVSession.getController();
console.info(`Succeeded in creating AV session, sessionId: ${this.sessionId}`);
(this.controller as avSession.AVSessionController).getExtras().then((extras) => {
console.info(`Succeeded in getting extras: ${extras}`);
});
});
}
build() {
Column() {
Text('AVSession Demo')
.fontSize(20)
.margin(10)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
} getExtras(callback: AsyncCallback<{[key: string]: Object}>): void
Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<{[key: string]: Object}> | Yes | Callback used to return the custom media packet. The content of the packet is the same as that set in setExtras. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
| 6600107 | Too many commands or events. |
Example
avcontroller.getExtras((err: BusinessError, extras) => {
if (err) {
console.error(`Failed to get extras, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting extras: ${extras}`);
}); getExtrasWithEvent(extraEvent: string): Promise<ExtraInfo>
Obtains the custom media packet set by the remote distributed media provider based on the remote distributed event type. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| extraEvent | string | Yes | Remote distributed event type. The event types that can be obtained from setExtras. For wearable devices, the following preset event types are additionally provided: 'AUDIO_GET_VOLUME': obtains the volume of the remote device. 'AUDIO_GET_AVAILABLE_DEVICES': obtains all remote devices that can be connected. 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO': obtains the actual remote audio device. |
Return value
| Type | Description |
|---|---|
| Promise<ExtraInfo> | Promise used to return the custom media packet set by the remote distributed media provider. The ExtraInfo parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see @ohos.app.ability.Want (Want). |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600105 | Invalid session command. |
Example
let controller: avSession.AVSessionController | undefined;
const COMMON_COMMAND_STRING_1 = 'AUDIO_GET_VOLUME';
const COMMON_COMMAND_STRING_2 = 'AUDIO_GET_AVAILABLE_DEVICES';
const COMMON_COMMAND_STRING_3 = 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO';
if (controller !== undefined) {
controller.getExtrasWithEvent(COMMON_COMMAND_STRING_1).then(() => {
console.info(`${[COMMON_COMMAND_STRING_1]}`);
})
controller.getExtrasWithEvent(COMMON_COMMAND_STRING_2).then(() => {
console.info(`${[COMMON_COMMAND_STRING_2]}`);
})
controller.getExtrasWithEvent(COMMON_COMMAND_STRING_3).then(() => {
console.info(`${[COMMON_COMMAND_STRING_3]}`);
})
} isDesktopLyricEnabled(): Promise<boolean>
Checks whether the desktop lyrics feature is enabled. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true indicates that the desktop lyrics feature is enabled, and false indicates the opposite. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600111 | The desktop lyrics feature is not supported. |
avcontroller.isDesktopLyricEnabled();
onDesktopLyricEnabled(callback: Callback<boolean>): void
Subscribes to the change events of the desktop lyrics feature enabling state. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<boolean> | Yes | Callback used to return the result. The value true indicates that the desktop lyrics feature is enabled, and false indicates the opposite. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.onDesktopLyricEnabled((enabled: boolean) => {
console.info(`desktop lyric enabled state : ${enabled}`);
}) offDesktopLyricEnabled(callback?: Callback<boolean>): void
Unsubscribes from the change events of the desktop lyrics enabling state. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<boolean> | No | Callback used to return the result. The value true indicates that the desktop lyrics feature is enabled, and false indicates the opposite. This parameter is optional. If it is not specified, the change events for the desktop lyrics enabling state of all sessions are unsubscribed. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.offDesktopLyricEnabled();
setDesktopLyricVisible(visible: boolean): Promise<void>
Sets whether to display desktop lyrics in the current session. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| visible | boolean | Yes | Whether to display desktop lyrics. true to display, false otherwise. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600110 | The desktop lyrics feature of this application is not enabled. |
| 6600111 | The desktop lyrics feature is not supported. |
Example
avcontroller.setDesktopLyricVisible(true);
isDesktopLyricVisible(): Promise<boolean>
Checks whether desktop lyrics are displayed in the current session. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. If true is returned, the desktop lyrics are displayed. If false is returned, the desktop lyrics are not displayed. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600110 | The desktop lyrics feature of this application is not enabled. |
| 6600111 | The desktop lyrics feature is not supported. |
Example
avcontroller.isDesktopLyricVisible();
onDesktopLyricVisibilityChanged(callback: Callback<boolean>): void
Subscribes to the change events of the desktop lyrics visibility. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<boolean> | Yes | Callback used to return the result. The value true indicates that the desktop lyrics are displayed, and false indicates the opposite. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.onDesktopLyricVisibilityChanged((visible: boolean) => {
console.info(`desktop lyric visible state: ${visible}`);
}); offDesktopLyricVisibilityChanged(callback?: Callback<boolean>): void
Unsubscribes from the change events of the desktop lyrics visibility. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<boolean> | No | Callback used to return the result. The value true indicates that the desktop lyrics are displayed, and false indicates the opposite. This parameter is optional. If it is not specified, the change events of all sessions' desktop lyrics visibility are unsubscribed. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.offDesktopLyricVisibilityChanged();
setDesktopLyricState(state: DesktopLyricState): Promise<void>
Sets the desktop lyric state of the current session. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| state | DesktopLyricState | Yes | Desktop lyrics state. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600110 | The desktop lyrics feature of this application is not enabled. |
| 6600111 | The desktop lyrics feature is not supported. |
Example
let state: avSession.DesktopLyricState = {
isLocked: true,
};
avcontroller.setDesktopLyricState(state); getDesktopLyricState(): Promise<DesktopLyricState>
Obtains the desktop lyric state of the current session. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<DesktopLyricState> | Promise used to return the state of the desktop lyric. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
| 6600110 | The desktop lyrics feature of this application is not enabled. |
| 6600111 | The desktop lyrics feature is not supported. |
Example
avcontroller.getDesktopLyricState();
onDesktopLyricStateChanged(callback: Callback<DesktopLyricState>): void
Subscribes to the change events of the desktop lyrics state. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<DesktopLyricState> | Yes | Callback used to return the desktop lyric state. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.onDesktopLyricStateChanged((state: avSession.DesktopLyricState) => {
console.info(`desktop lyric isLocked : ${state.isLocked}`);
}) offDesktopLyricStateChanged(callback?: Callback<DesktopLyricState>): void
Unsubscribes from the change events of the desktop lyrics state. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<DesktopLyricState> | No | Callback used to return the desktop lyrics state. This parameter is optional. If it is not specified, the change events of all sessions' desktop lyrics state are unsubscribed. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.offDesktopLyricStateChanged();
on(type: 'metadataChange', filter: Array<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
Subscribes to metadata change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'metadataChange' is triggered when the session metadata requires an update. "Requires an update" means the corresponding property value has been reset, regardless of whether the new value matches the old one. |
| filter | Array<keyof AVMetadata>|'all' | Yes | Array<keyof AVMetadata> indicates monitoring for updates to fields in the array. The value 'all' indicates monitoring for updates to all metadata fields. |
| callback | (data: AVMetadata) => void | Yes | Callback used to return the result. The data parameter in the callback indicates the changed metadata. It contains only the changed metadata attributes and does not represent the complete current metadata set. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
console.info(`on metadataChange assetId : ${metadata.assetId}`);
});
avcontroller.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
console.info(`on metadataChange assetId : ${metadata.assetId}`);
}); off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
Unsubscribes from metadata change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'metadataChange' event is supported. |
| callback | (data: AVMetadata) => void | No | Callback used to return the result. The data parameter in the callback indicates the changed metadata. It contains only the changed metadata attributes and does not represent the complete current metadata set. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('metadataChange'); on(type: 'playbackStateChange', filter: Array<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
Subscribes to playback state change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'playbackStateChange' is triggered when the playback state requires an update. "Requires an update" means the corresponding property value has been reset, regardless of whether the new value matches the old one. |
| filter | Array<keyof AVPlaybackState>|'all' | Yes | Array<keyof AVPlaybackState> indicates monitoring for updates to fields in the array. The value 'all' indicates monitoring for updates to all playback state fields, |
| callback | (state: AVPlaybackState) => void | Yes | Callback function, where the state parameter indicates the playback state that requires an update, but not the complete current playback state set. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
console.info(`on playbackStateChange state : ${playbackState.state}`);
});
avcontroller.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
console.info(`on playbackStateChange state : ${playbackState.state}`);
}); off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
Unsubscribes from playback state change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'playbackStateChange' event is supported. |
| callback | (state: AVPlaybackState) => void | No | Callback function, where the state parameter indicates the playback state that requires an update, but not the complete current playback state set. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('playbackStateChange'); on(type: 'callMetadataChange', filter: Array<keyof CallMetadata> | 'all', callback: Callback<CallMetadata>): void
Subscribes to call metadata change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'callMetadataChange' is triggered when the call metadata changes. |
| filter | Array<keyof CallMetadata>|'all' | Yes | Array<keyof CallMetadata> indicates monitoring for updates to fields in the array. The value 'all' indicates monitoring for updates to all call metadata fields. |
| callback | Callback<CallMetadata> | Yes | Callback used to return the result. The callmetadata parameter in the callback indicates the changed call metadata. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => {
console.info(`on callMetadataChange state : ${callmetadata.name}`);
});
avcontroller.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => {
console.info(`on callMetadataChange state : ${callmetadata.name}`);
}); off(type: 'callMetadataChange', callback?: Callback<CallMetadata>): void
Unsubscribes from call metadata change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'callMetadataChange' event is supported. |
| callback | Callback<CallMetadata> | No | Callback used to return the result. The calldata parameter in the callback indicates the changed call metadata. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('callMetadataChange'); on(type: 'callStateChange', filter: Array<keyof AVCallState> | 'all', callback: Callback<AVCallState>): void
Subscribes to call state change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'callStateChange' is triggered when the call state changes. |
| filter | Array<keyof AVCallState>|'all' | Yes | Array<keyof AVCallState> indicates monitoring for updates to fields in the array. The value 'all' indicates monitoring for updates to all call state fields. |
| callback | Callback<AVCallState> | Yes | Callback used to return the result, where the callstate parameter indicates the new call state. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified.2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('callStateChange', 'all', (callstate: avSession.AVCallState) => {
console.info(`on callStateChange state : ${callstate.state}`);
});
avcontroller.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => {
console.info(`on callStateChange state : ${callstate.state}`);
}); off(type: 'callStateChange', callback?: Callback<AVCallState>): void
Unsubscribes from call state change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'callStateChange' event is supported. |
| callback | Callback<AVCallState> | No | Callback used to return the result, where the callstate parameter indicates the new call state. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('callStateChange'); on(type: 'sessionDestroy', callback: () => void)
Subscribes to session destruction events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. Event 'sessionDestroy' is triggered when a session is destroyed. |
| callback | () => void | Yes | Callback invoked when a session is destroyed. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('sessionDestroy', () => {
console.info('Succeeded in session destroy.');
}); off(type: 'sessionDestroy', callback?: () => void)
Unsubscribes from session destruction events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'sessionDestroy' event is supported. |
| callback | () => void | No | Callback used to return the result, which is the same as that registered using the on method. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified.2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('sessionDestroy'); on(type: 'activeStateChange', callback: (isActive: boolean) => void)
Subscribes to session activation state change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'activeStateChange' is triggered when the activation state of the session changes. |
| callback | (isActive: boolean) => void | Yes | Callback used to return the result. The isActive parameter in the callback specifies whether the session is activated. true if activated, false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('activeStateChange', (isActive: boolean) => {
console.info(`Succeeded in active state change: ${isActive}`);
}); off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
Unsubscribes from session activation state change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'activeStateChange' event is supported. |
| callback | (isActive: boolean) => void | No | Callback used to return the result. The isActive parameter in the callback specifies whether the session is activated. true if activated, false otherwise. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('activeStateChange'); on(type: 'validCommandChange', callback: (commands: Array<AVControlCommandType>) => void)
Subscribes to valid command change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'validCommandChange' is triggered when the valid commands supported by the session changes. |
| callback | (commands: Array<AVControlCommandType>) => void | Yes | Callback used to return the result. The commands parameter in the callback is a set of valid commands. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
console.info(`Succeeded in valid command change, size: ${validCommands.length}`);
console.info(`Succeeded in valid command change, validCommands: ${validCommands.values()}`);
}); off(type: 'validCommandChange', callback?: (commands: Array<AVControlCommandType>) => void)
Unsubscribes from valid command change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'validCommandChange' event is supported. |
| callback | (commands: Array<AVControlCommandType>) => void | No | Callback used to return the result. The commands parameter in the callback is a set of valid commands. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('validCommandChange'); on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
Subscribes to output device change events.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'outputDeviceChange' is triggered when the output device changes. |
| callback | (state: ConnectionState, device: OutputDeviceInfo) => void | Yes | Callback used to return the result. The device parameter in the callback indicates the output device information. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
}); off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
Unsubscribes from output device change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'outputDeviceChange' event is supported. |
| callback | (state: ConnectionState, device: OutputDeviceInfo) => void | No | Callback function, where the device parameter specifies the output device information. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('outputDeviceChange'); on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key: string]: Object}) => void): void
Subscribes to session event change events. This API is called by the controller.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'sessionEvent' is triggered when the session event changes. |
| callback | (sessionEvent: string, args: {[key: string]: Object}) => void | Yes | Callback used to return the result. sessionEvent in the callback indicates the name of the session event that changes, and args indicates the parameters carried in the event. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
// Index.ets
avcontroller.on('sessionEvent', (sessionEvent, args) => {
console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
}); off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key: string]: Object}) => void): void
Unsubscribes from session events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'sessionEvent' event is supported. |
| 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. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('sessionEvent'); on(type: 'queueItemsChange', callback: (items: Array<AVQueueItem>) => void): void
Subscribes to playlist item change events. This API is called by the controller.
Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'queueItemsChange' is triggered when one or more items in the playlist changes. |
| callback | (items: Array<AVQueueItem>) => void | Yes | Callback used to return the result. The items parameter in the callback indicates the changed items in the playlist. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
console.info(`OnQueueItemsChange, items length is ${items.length}`);
}); off(type: 'queueItemsChange', callback?: (items: Array<AVQueueItem>) => void): void
Unsubscribes from playback item change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'queueItemsChange' event is supported. |
| callback | (items: Array<AVQueueItem>) => void | No | Callback used for unsubscription. The items parameter in the callback indicates the changed items in the playlist. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('queueItemsChange'); on(type: 'queueTitleChange', callback: (title: string) => void): void
Subscribes to playlist name change events. This API is called by the controller.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'queueTitleChange' is triggered when the playlist name changes. |
| callback | (title: string) => void | Yes | Callback used to return the result. The title parameter in the callback indicates the changed playlist name. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('queueTitleChange', (title: string) => {
console.info(`queueTitleChange, title is ${title}`);
}); off(type: 'queueTitleChange', callback?: (title: string) => void): void
Unsubscribes from playlist name change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'queueTitleChange' event is supported. |
| callback | (title: string) => void | No | Callback used for unsubscription. The title parameter in the callback indicates the changed playlist name. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('queueTitleChange'); on(type: 'extrasChange', callback: (extras: {[key: string]: Object}) => void): void
Subscribes to custom media packet change events. This API is called by the controller.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'extrasChange' is triggered when the provider sets a custom media packet. |
| callback | (extras: {[key: string]: Object}) => void | Yes | Callback used to return the result. 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. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('extrasChange', (extras) => {
console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
}); off(type: 'extrasChange', callback?: (extras: {[key: string]: Object}) => void): void
Unsubscribes from custom media packet change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'extrasChange' event is supported. |
| callback | (extras: {[key: string]: Object}) => void | No | Callback used to return the result. extras indicates the custom media data packet newly set by the media provider. This parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see Universal Error Codes and AVSession Error Codes.
| ID | Error Message |
|---|---|
| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('extrasChange'); on(type: 'customDataChange', callback: Callback<Record<string, Object>>): void
Subscribes to events indicating that custom data is sent to a remote device.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.Multimedia.AVSession.AVCast
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The event 'customDataChange' is triggered when the provider sends custom data. |
| callback | Callback<Record<string, Object>> | Yes | Callback used to receive the custom data. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.on('customDataChange', (data) => {
console.info(`Caught customDataChange event,the new data is: ${JSON.stringify(data)}`);
}); off(type: 'customDataChange', callback?: Callback<Record<string, Object>>): void
Unsubscribes from events indicating that custom data is sent to a remote device.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.Multimedia.AVSession.AVCast
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Type of the event to be unsubscribed from. Currently, only the 'customDataChange' event is supported. |
| callback | Callback<Record<string, Object>> | No | Callback used to receive the custom data. The callback parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.off('customDataChange'); getAVPlaybackStateSync(): AVPlaybackState;
Obtains the playback state of this session. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| AVPlaybackState | Playback state of the session. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let playbackState: avSession.AVPlaybackState = avcontroller.getAVPlaybackStateSync();
getAVMetadataSync(): AVMetadata
Obtains the session metadata. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| AVMetadata | Session metadata. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let metaData: avSession.AVMetadata = avcontroller.getAVMetadataSync();
getAVCallState(): Promise<AVCallState>
Obtains the call state. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<AVCallState> | Promise used to return the call state obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVCallState().then((callstate: avSession.AVCallState) => {
console.info(`Succeeded in getting AV call state: ${callstate.state}`);
}); getAVCallState(callback: AsyncCallback<AVCallState>): void
Obtains the call state. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<AVCallState> | Yes | Callback used to return the call state obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => {
if (err) {
console.error(`Failed to get AV call state, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting AV call state: ${callstate.state}`);
}); getCallMetadata(): Promise<CallMetadata>
Obtains the call metadata. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<CallMetadata> | Promise used to return the metadata obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getCallMetadata().then((calldata: avSession.CallMetadata) => {
console.info(`Succeeded in getting call metadata, name: ${calldata.name}`);
}); getCallMetadata(callback: AsyncCallback<CallMetadata>): void
Obtains the call metadata. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<CallMetadata> | Yes | Callback used to return the metadata obtained. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => {
if (err) {
console.error(`Failed to get call metadata, code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting call metadata, name: ${calldata.name}`);
}); getAVQueueTitleSync(): string
Obtains the name of the playlist of this session. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| string | Playlist name. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let currentQueueTitle: string = avcontroller.getAVQueueTitleSync();
getAVQueueItemsSync(): Array<AVQueueItem>
Obtains the information related to the items in the playlist of this session. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Array<AVQueueItem> | Items in the queue. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let currentQueueItems: Array<avSession.AVQueueItem> = avcontroller.getAVQueueItemsSync();
getOutputDeviceSync(): OutputDeviceInfo
Obtains the output device information. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| OutputDeviceInfo | Information about the output device. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
let currentOutputDevice: avSession.OutputDeviceInfo = avcontroller.getOutputDeviceSync();
isActiveSync(): boolean
Checks whether the session is activated. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| boolean | Check result for whether the session is activated. true if activated, false otherwise. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let isActive: boolean = avcontroller.isActiveSync();
getValidCommandsSync(): Array<AVControlCommandType>
Obtains valid commands supported by the session. This API returns the result synchronously.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Array<AVControlCommandType> | A set of valid commands. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600102 | The session does not exist. |
| 6600103 | The session controller does not exist. |
Example
let validCommands: Array<avSession.AVControlCommandType> = avcontroller.getValidCommandsSync();
getSupportedPlaySpeeds(): Promise<Array<number>>
Obtains the playback speeds supported by the application. This API uses a promise to return the result.
The playback speeds are set using the setSupportedPlaySpeeds API. If the application has not set any playback speed or has set an empty array, an empty array is returned.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<Array<number>> | Promise used to return an array of supported playback speeds. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getSupportedPlaySpeeds().then((speeds: number[]) => {
console.info(`Succeeded in getting supported play speeds, size: ${speeds.length}`);
}); getSupportedLoopModes(): Promise<Array<LoopMode>>
Obtains the loop modes supported by the application. This API uses a promise to return the result.
The loop modes are set using the setSupportedLoopModes API. If the application has not set any loop mode or has set an empty array, an empty array is returned.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<Array<LoopMode>> | Promise used to return an array of loop modes supported by the application. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getSupportedLoopModes().then((loopModes: avSession.LoopMode[]) => {
console.info(`Succeeded in getting supported loop modes, size: ${loopModes.length}`);
}); getMediaCenterControlType(): Promise<Array<AVMediaCenterControlType>>
Obtains the control types with display priorities set using setMediaCenterControlType. This API uses a promise to return the result.
If the application has not set any control type or has set an empty array, an empty array is returned.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Return value
| Type | Description |
|---|---|
| Promise<Array<AVMediaCenterControlType>> | Promise used to return an array of control types with display priorities. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.getMediaCenterControlType().then((types: avSession.AVMediaCenterControlType[]) => {
console.info(`Succeeded in getting media center control types, size: ${types.length}`);
}); onMediaCenterControlTypeChanged(callback: Callback<Array<AVMediaCenterControlType>>): void
Subscribes to control type change events. This API uses an asynchronous callback to return the result.
The control types are set using the setMediaCenterControlType API.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<Array<AVMediaCenterControlType>> | Yes | Callback used to return an array of control types after the change. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.onMediaCenterControlTypeChanged((types: avSession.AVMediaCenterControlType[]) => {
console.info(`Media center control types changed, size: ${types.length}`);
}); offMediaCenterControlTypeChanged(callback?: Callback<Array<AVMediaCenterControlType>>): void
Unsubscribes from control type change events.
The control types are set using the setMediaCenterControlType API.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<Array<AVMediaCenterControlType>> | No | Callback used to return the result. This parameter is optional. If it is not specified, all control type change events are unsubscribed from. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.offMediaCenterControlTypeChanged();
onSupportedPlaySpeedsChange(callback: Callback<Array<number>>): void
Subscribes to playback speed change events. This API uses an asynchronous callback to return the result.
The playback speeds are set using the setSupportedPlaySpeeds API.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<Array<number>> | Yes | Callback used to return an array of supported playback speeds after the change. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.onSupportedPlaySpeedsChange((speeds: number[]) => {
console.info(`Supported play speeds changed, size: ${speeds.length}`);
}); offSupportedPlaySpeedsChange(callback?: Callback<Array<number>>): void
Unsubscribes from playback speed change events.
The playback speeds are set using the setSupportedPlaySpeeds API.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<Array<number>> | No | Callback used to return the result. This parameter is optional. If it is not specified, all playback speed change events are unsubscribed from. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.offSupportedPlaySpeedsChange();
onSupportedLoopModesChange(callback: Callback<Array<LoopMode>>): void
Subscribes to supported loop mode change events. This API uses an asynchronous callback to return the result.
The loop modes are set using the setSupportedLoopModes API.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<Array<LoopMode>> | Yes | Callback used to return an array of supported loop modes after the change. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.onSupportedLoopModesChange((loopModes: avSession.LoopMode[]) => {
console.info(`Supported loop modes changed, size: ${loopModes.length}`);
}); offSupportedLoopModesChange(callback?: Callback<Array<LoopMode>>): void
Unsubscribes from supported loop mode change events.
The loop modes are set using the setSupportedLoopModes API.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 26.0.0.
System capability: SystemCapability.Multimedia.AVSession.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | Callback<Array<LoopMode>> | No | Callback used to return the result. This parameter is optional. If it is not specified, all supported loop mode change events are unsubscribed from. |
Error codes
For details about the error codes, see AVSession Management Error Codes.
| ID | Error Message |
|---|---|
| 6600101 | Session service exception. |
| 6600103 | The session controller does not exist. |
Example
avcontroller.offSupportedLoopModesChange();