diff --git a/en/application-dev/application-models/application-context-stage.md b/en/application-dev/application-models/application-context-stage.md index 17fe99577ab5cd782bcd4154274555bb8064da24..47fdeeedf1fe5238b0f0a2e56945be35208e0391 100644 --- a/en/application-dev/application-models/application-context-stage.md +++ b/en/application-dev/application-models/application-context-stage.md @@ -86,13 +86,13 @@ The application file paths obtained by the preceding contexts are different. | Name| Path| | -------- | -------- | - | bundleCodeDir | \/el1/bundle/| - | cacheDir | \/\/base/cache/| - | filesDir | \/\/base/files/| - | preferencesDir | \/\/base/preferences/| - | tempDir | \/\/base/temp/| - | databaseDir | \/\/database/| - | distributedFilesDir | \/el2/distributedFiles/| + | bundleCodeDir | \/el1/bundle| + | cacheDir | \/\/base/cache| + | filesDir | \/\/base/files| + | preferencesDir | \/\/base/preferences| + | tempDir | \/\/base/temp| + | databaseDir | \/\/database| + | distributedFilesDir | \/el2/distributedFiles| The sample code is as follows: @@ -110,6 +110,9 @@ The application file paths obtained by the preceding contexts are different. let distributedFilesDir = applicationContext.distributedFilesDir; let preferencesDir = applicationContext.preferencesDir; ... + // Obtain the application file path. + let filePath = tempDir + 'test.txt'; + console.info(`filePath: ${filePath}`); } } ``` @@ -118,13 +121,13 @@ The application file paths obtained by the preceding contexts are different. | Name| Path| | -------- | -------- | - | bundleCodeDir | \/el1/bundle/| - | cacheDir | \/\/base/**haps/\**/cache/| - | filesDir | \/\/base/**haps/\**/files/| - | preferencesDir | \/\/base/**haps/\**/preferences/| - | tempDir | \/\/base/**haps/\**/temp/| - | databaseDir | \/\/database/**\**/| - | distributedFilesDir | \/el2/distributedFiles/**\**/| + | bundleCodeDir | \/el1/bundle| + | cacheDir | \/\/base/**haps/\**/cache| + | filesDir | \/\/base/**haps/\**/files| + | preferencesDir | \/\/base/**haps/\**/preferences| + | tempDir | \/\/base/**haps/\**/temp| + | databaseDir | \/\/database/**\**| + | distributedFilesDir | \/el2/distributedFiles/**\**| The sample code is as follows: @@ -141,6 +144,9 @@ The application file paths obtained by the preceding contexts are different. let distributedFilesDir = this.context.distributedFilesDir; let preferencesDir = this.context.preferencesDir; ... + // Obtain the application file path. + let filePath = tempDir + 'test.txt'; + console.info(`filePath: ${filePath}`); } } ``` diff --git a/en/application-dev/application-models/hop-cross-device-migration.md b/en/application-dev/application-models/hop-cross-device-migration.md index 92c254514d82cbcfe800f5b35bfefb96411a8f92..b452d8ea493bbfe060094f13073b9bdd9eac4f65 100644 --- a/en/application-dev/application-models/hop-cross-device-migration.md +++ b/en/application-dev/application-models/hop-cross-device-migration.md @@ -53,9 +53,9 @@ The table below describes the main APIs used for cross-device migration. For det | **API**| Description| | -------- | -------- | -| onContinue(wantParam : {[key: string]: any}): OnContinueResult | Called by the initiator to store the data required for migration and indicate whether the migration is accepted.
- **AGREE**: The migration is accepted.
- **REJECT**: The migration is rejected, for example, when an application is abnormal in **onContinue()**.
- **MISMATCH**: The version does not match. The application on the initiator can obtain the version number of the target application from **onContinue()**. If the migration cannot be performed due to version mismatch, this error code is returned.| -| onCreate(want: Want, param: AbilityConstant.LaunchParam): void; | Called by the target to restore the data and UI page in the multiton migration scenario. For details, see [UIAbility Component Launch Type](uiability-launch-type.md).| -| onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; | Called by the target to restore the data and UI page in the singleton migration scenario. For details, see [UIAbility Component Launch Type](uiability-launch-type.md).| +| onContinue(wantParam : {[key: string]: Object}): OnContinueResult | Called by the initiator to store the data required for migration and indicate whether the migration is accepted.
- **AGREE**: The migration is accepted.
- **REJECT**: The migration is rejected, for example, when an application is abnormal in **onContinue()**.
- **MISMATCH**: The version does not match. The application on the initiator can obtain the version number of the target application from **onContinue()**. If the migration cannot be performed due to version mismatch, this error code is returned.| +| onCreate(want: Want, param: AbilityConstant.LaunchParam): void; | Called by the target to restore the data and UI page when the target uses cold start or the target is a multiton application and uses hot start. For details, see [UIAbility Component Launch Type](uiability-launch-type.md).| +| onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; | Called by the target to restore the data and UI page when the target is a singleton application and uses hot start. For details, see [UIAbility Component Launch Type](uiability-launch-type.md).| @@ -90,7 +90,7 @@ The table below describes the main APIs used for cross-device migration. For det 4. Implement [onContinue()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) in the UIAbility of the initiator. - [onContinue()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) is called on the initiator. You can save the data in this method to implement application compatibility check and migration decision. + [onContinue()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) is called on the initiator. You can save the data in this method to implement application compatibility check and migration decision. - Saving migrated data: You can save the data to be migrated in key-value pairs in **wantParam**. - Checking application compatibility: You can obtain the version number of the target application from **wantParam** and that of the current application from **wantParam.version** of the **onContinue()** callback. Then you can check the compatibility between the two. @@ -114,7 +114,7 @@ The table below describes the main APIs used for cross-device migration. For det ``` 5. Implement **onCreate()** and **onNewWant()** in the UIAbility of the target application to implement data restoration. - - Implementation example of **onCreate** in the multiton scenario + - Implementation example of **onCreate** - The target device determines whether the startup is **LaunchReason.CONTINUATION** based on **launchReason** in **onCreate()**. - You can obtain the saved migration data from the **want** parameter. - After data restoration is complete, call **restoreWindowStage** to trigger page restoration, including page stack information. @@ -139,11 +139,29 @@ The table below describes the main APIs used for cross-device migration. For det } } ``` - - For a singleton ability, use **onNewWant()** to achieve the same implementation. + - For a singleton application, you must also implement **onNewWant()**, in the same way as **onCreate()**. + - Determine the migration scenario in **onNewWant()**, restore data, and trigger page restoration. + ```ts + export default class EntryAbility extends UIAbility { + storage : LocalStorage; + onNewWant(want, launchParam) { + console.info(`EntryAbility onNewWant ${AbilityConstant.LaunchReason.CONTINUATION}`) + if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) { + // Obtain the user data from the want parameter. + let workInput = want.parameters.work + console.info(`work input ${workInput}`) + AppStorage.SetOrCreate('ContinueWork', workInput) + this.storage = new LocalStorage(); + this.context.restoreWindowStage(this.storage); + } + } + } + ``` + 6. (Optional) Call [setMissionContinueState](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextsetmissioncontinuestate10) to set the mission continuation state. - For an application that supports migration, mission migration is enabled by default, and the system notifies peripheral trusted devices that a mission can be migrated or canceled based on the gain/loss focus state of the mission. If you want the system to send a notification to peripheral devices only when your application is in a specific scenario, set the migration continuation state to **INACTIVE** when the application is started and change it to **ACTIVE** when the application enters that specific scenario. For details about the API, see [setMissionContinueState](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextsetmissioncontinuestate10). + For an application that supports migration, mission migration is enabled by default, and the system notifies peripheral trusted devices that a mission can be migrated or canceled based on the gain/loss focus state of the mission. If you want the system to send a notification to peripheral devices only when your application is in a specific scenario, set the migration continuation state to **INACTIVE** when the application is started and change it to **ACTIVE** when the application enters that specific scenario. - Example: An application does not require migration during startup. @@ -180,7 +198,7 @@ The table below describes the main APIs used for cross-device migration. For det onContinue(wantParam : {[key: string]: any}) { console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`) - wantParam[wantConstant.SUPPORT_CONTINUE_PAGE_STACK_KEY] = false; + wantParam[wantConstant.Params.SUPPORT_CONTINUE_PAGE_STACK_KEY] = false; return AbilityConstant.OnContinueResult.AGREE; } @@ -202,7 +220,7 @@ The table below describes the main APIs used for cross-device migration. For det onContinue(wantParam : {[key: string]: any}) { console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`) - wantParam[wantConstant.SUPPORT_CONTINUE_SOURCE_EXIT_KEY] = false; + wantParam[wantConstant.Params.SUPPORT_CONTINUE_SOURCE_EXIT_KEY] = false; return AbilityConstant.OnContinueResult.AGREE; } ``` diff --git a/en/application-dev/application-models/medialibrary-switch.md b/en/application-dev/application-models/medialibrary-switch.md index dc671d1b61b467f98d7d01f43703b165df4c1e52..b5c8891f21fd2a554a2905f0f1cce59847e7f8ad 100644 --- a/en/application-dev/application-models/medialibrary-switch.md +++ b/en/application-dev/application-models/medialibrary-switch.md @@ -1,6 +1,6 @@ # mediaLibrary Switching - | API in the FA Model| Corresponding .d.ts File in the Stage Model| Corresponding API in the Stage Model| +| API in the FA Model| Corresponding .d.ts File in the Stage Model| Corresponding API in the Stage Model| | -------- | -------- | -------- | -| [getMediaLibrary(): MediaLibrary;](../reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) | \@ohos.multimedia.mediaLibrary.d.ts | [getMediaLibrary(context: Context): MediaLibrary;](../reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary8) | +| [getMediaLibrary(): MediaLibrary;](../reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) | \@ohos.file.photoAccessHelper.d.ts | [getPhotoAccessHelper(context: Context): PhotoAccessHelper;](../reference/apis/js-apis-photoAccessHelper.md#photoaccesshelpergetphotoaccesshelper) | diff --git a/en/application-dev/device/figures/001.png b/en/application-dev/device/figures/001.png new file mode 100644 index 0000000000000000000000000000000000000000..0b173958ed943fb9ecebd686b4f378d93fa2a7b0 Binary files /dev/null and b/en/application-dev/device/figures/001.png differ diff --git a/en/application-dev/device/figures/002.png b/en/application-dev/device/figures/002.png new file mode 100644 index 0000000000000000000000000000000000000000..34af38f77c66cbef900a1a4e536e3873bd0d94aa Binary files /dev/null and b/en/application-dev/device/figures/002.png differ diff --git a/en/application-dev/device/figures/003.png b/en/application-dev/device/figures/003.png new file mode 100644 index 0000000000000000000000000000000000000000..3c95c64ccb305ec25b1927733615ec4553505f97 Binary files /dev/null and b/en/application-dev/device/figures/003.png differ diff --git a/en/application-dev/device/sensor-guidelines.md b/en/application-dev/device/sensor-guidelines.md index 6ff5eb7405027da0853737ba64959cec4e59ad3a..21e1b55296ac46606bf1e4c91859f4c1f03ce030 100644 --- a/en/application-dev/device/sensor-guidelines.md +++ b/en/application-dev/device/sensor-guidelines.md @@ -15,65 +15,64 @@ For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md). | ohos.sensor | sensor.on(sensorId, callback:AsyncCallback<Response>): void | Subscribes to data changes of a type of sensor.| | ohos.sensor | sensor.once(sensorId, callback:AsyncCallback<Response>): void | Subscribes to only one data change of a type of sensor.| | ohos.sensor | sensor.off(sensorId, callback?:AsyncCallback<void>): void | Unsubscribes from sensor data changes.| +| ohos.sensor | sensor.getSensorList(callback: AsyncCallback\>): void| Obtains information about all sensors on the device. This API uses an asynchronous callback to return the result.| ## How to Develop -1. Before obtaining data from a type of sensor, check whether the required permission has been configured.
- The system provides the following sensor-related permissions: - - ohos.permission.ACCELEROMETER +The acceleration sensor is used as an example. - - ohos.permission.GYROSCOPE +1. Import the module. - - ohos.permission.ACTIVITY_MOTION - - - ohos.permission.READ_HEALTH_DATA - - For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md). - -2. Subscribe to data changes of a type of sensor. The following uses the acceleration sensor as an example. - ```ts import sensor from "@ohos.sensor"; - - sensor.on(sensor.SensorId.ACCELEROMETER, function (data) { - console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. - }); ``` - - ![171e6f30-a8d9-414c-bafa-b430340305fb](figures/171e6f30-a8d9-414c-bafa-b430340305fb.png) -3. Unsubscribe from sensor data changes. - - ```ts - import sensor from "@ohos.sensor"; - sensor.off(sensor.SensorId.ACCELEROMETER); - ``` - - ![65d69983-29f6-4381-80a3-f9ef2ec19e53](figures/65d69983-29f6-4381-80a3-f9ef2ec19e53.png) +2. Obtain information about all sensors on the device. + + ```ts + sensor.getSensorList(function (error, data) { + if (error) { + console.info('getSensorList failed'); + } else { + console.info('getSensorList success'); + for (let i = 0; i < data.length; i++) { + console.info(JSON.stringify(data[i])); + } + } + }); + ``` -4. Subscribe to only one data change of a type of sensor. - - ```ts - import sensor from "@ohos.sensor"; + ![](figures/001.png) - sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { - console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. - }); - ``` - - ![db5d017d-6c1c-4a71-a2dd-f74b7f23239e](figures/db5d017d-6c1c-4a71-a2dd-f74b7f23239e.png) + The minimum and the maximum sampling periods supported by the sensor are 5000000 ns and 200000000 ns, respectively. Therefore, the value of **interval** must be within this range. + +3. Check whether the corresponding permission has been configured. For details, see [Applying for Permissions](../security/accesstoken-guidelines.md). - If the API fails to be called, you are advised to use the **try/catch** statement to capture error information that may occur in the code. Example: +4. Register a listener. You can call **on()** or **once()** to listen for sensor data changes. + +- The **on()** API is used to continuously listen for data changes of the sensor. The sensor reporting interval is set to 100000000 ns. + + ```ts + sensor.on(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + " y: " + data.y + " z: " + data.z); + }, {'interval': 100000000}); + ``` + + ![](figures/002.png) + +- The **once()** API is used to listen for only one data change of the sensor. ```ts - import sensor from "@ohos.sensor"; + sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + " y: " + data.y + " z: " + data.z); + }); + ``` + + ![](figures/003.png) - try { - sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { - console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. - }); - } catch (error) { - console.error(`Failed to get sensor data. Code: ${error.code}, message: ${error.message}`); - } +5. Cancel continuous listening. + + ```ts + sensor.off(sensor.SensorId.ACCELEROMETER); ``` diff --git a/en/application-dev/device/vibrator-guidelines.md b/en/application-dev/device/vibrator-guidelines.md index 7d3434d680d0d1a369d4f0ccd0bc8f720bd71349..4619a52a2f91c94b06e529be68d78330b4a4719f 100644 --- a/en/application-dev/device/vibrator-guidelines.md +++ b/en/application-dev/device/vibrator-guidelines.md @@ -76,9 +76,9 @@ This JSON file contains two attributes: **MetaData** and **Channels**. - **Create**: time when the file was created. This parameter is optional. - **Description**: additional information such as the vibration effect and creation information. This parameter is optional. - **Channels** provides information about the vibration channel. It is a JSON array that holds information about each channel. It contains two attributes: **Parameters** and **Pattern**. -- **Parameters** provides parameters related to the channel. Under it, **Index** indicates the channel ID. The value is fixed at **1** for a single channel. This parameter is mandatory. + - **Parameters** provides parameters related to the channel. Under it, **Index** indicates the channel ID. The value is fixed at **1** for a single channel. This parameter is mandatory. - **Pattern** indicates the vibration sequence. It is a JSON array. Under it, **Event** indicates a vibration event, which can be either of the following types: -- **transient**: short vibration + - **transient**: short vibration - **continuous**: long vibration The table below describes the parameters under **Event**. @@ -89,7 +89,7 @@ The table below describes the parameters under **Event**. | StartTime | Start time of the vibration. This parameter is mandatory.| [0, 1800 000], in ms, without overlapping| | Duration | Duration of the vibration. This parameter is valid only when **Type** is **continuous**.| (10, 1600), in ms| | Intensity | Intensity of the vibration. This parameter is mandatory.| [0, 100], a relative value that does not represent the actual vibration strength.| -| Frequency | Frequency of the vibration. This parameter is mandatory.| [0, 100], a relative value that does not represent the actual vibration frequency| +| Frequency | Frequency of the vibration. This parameter is mandatory.| [0, 100], a relative value that does not represent the actual vibration frequency.| The following requirements must be met: @@ -221,45 +221,42 @@ The following requirements must be met: ```ts import vibrator from '@ohos.vibrator'; - const FILE_NAME = "xxx.json"; - // Obtain the file descriptor of the vibration configuration file. - let fileDescriptor = undefined; - getContext().resourceManager.getRawFd(FILE_NAME).then(value => { - fileDescriptor = { fd: value.fd, offset: value.offset, length: value.length }; - console.info('Succeed in getting resource file descriptor'); - }).catch(error => { - console.error(`Failed to get resource file descriptor. Code: ${error.code}, message: ${error.message}`); - }); - // To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission. - try { - // Start custom vibration. - vibrator.startVibration({ - type: "file", - hapticFd: { fd: fileDescriptor.fd, offset: fileDescriptor.offset, length: fileDescriptor.length } - }, { - usage: "alarm" - }).then(() => { - console.info('Succeed in starting vibration'); - }, (error) => { - console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); - }); - // Stop vibration in all modes. - vibrator.stopVibration(function (error) { - if (error) { - console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); - return; - } - console.info('Succeed in stopping vibration'); - }) - } catch (error) { - console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + async function getRawfileFd(fileName) { + let rawFd = await globalThis.getContext().resourceManager.getRawFd(fileName); + return rawFd; + } + + // Close the file descriptor of the vibration configuration file. + async function closeRawfileFd(fileName) { + await globalThis.getContext().resourceManager.closeRawFd(fileName) + } + + // Play the custom vibration. To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission. + async function playCustomHaptic(fileName) { + try { + let rawFd = await getRawfileFd(fileName); + vibrator.startVibration({ + type: "file", + hapticFd: { fd: rawFd.fd, offset: rawFd.offset, length: rawFd.length } + }, { + usage: "alarm" + }).then(() => { + console.info('Succeed in starting vibration'); + }, (error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); + vibrator.stopVibration(function (error) { + if (error) { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in stopping vibration'); + }) + await closeRawfileFd(fileName); + } catch (error) { + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + } } - // Close the vibration file. - getContext().resourceManager.closeRawFd(FILE_NAME).then(() => { - console.info('Succeed in closing resource file descriptor'); - }).catch(error => { - console.error(`Failed to close resource file descriptor. Code: ${error.code}, message: ${error.message}`); - }); ``` diff --git a/en/application-dev/media/audio-effect-management.md b/en/application-dev/media/audio-effect-management.md index e1de3111d8b776c87e5bf772b33ea619df813ced..884a9a9636e23f46b44ae73e5e75756bea27f438 100644 --- a/en/application-dev/media/audio-effect-management.md +++ b/en/application-dev/media/audio-effect-management.md @@ -91,7 +91,7 @@ Enable the default system audio effect. ## Obtaining the Global Audio Effect Mode -You can obtain the global audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**). +You can obtain the global audio effect mode corresponding to a specific audio stream usage (specified by **StreamUsage**). For an audio playback application, pay attention to the audio effect mode used by the audio stream of the application and perform corresponding operations. For example, for a music application, select the audio effect mode for the music scenario. Before obtaining the global audio effect mode, call **getStreamManager()** to create an **AudioStreamManager** instance. ### Creating an AudioStreamManager Instance @@ -107,7 +107,7 @@ Create an **AudioStreamManager** instance. Before using **AudioStreamManager** A ### Querying the Audio Effect Mode of the Corresponding Scenario ```js - audioStreamManager.getAudioEffectInfoArray(audio.ContentType.CONTENT_TYPE_MUSIC, audio.StreamUsage.STREAM_USAGE_MEDIA, async (err, audioEffectInfoArray) => { + audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA, async (err, audioEffectInfoArray) => { if (err) { console.error('Failed to get effect info array'); return; diff --git a/en/application-dev/reference/apis/js-apis-avsession.md b/en/application-dev/reference/apis/js-apis-avsession.md index b2ad9fb70720b8d56ee05c19a59c12183a3cf199..e03f438f967881b19965c713016e399c1a0eeeb6 100644 --- a/en/application-dev/reference/apis/js-apis-avsession.md +++ b/en/application-dev/reference/apis/js-apis-avsession.md @@ -6,6 +6,7 @@ This module provides the following typical features related to media sessions: - [AVSession](#avsession10): used to set session metadata, playback state information, and more. - [AVSessionController](#avsessioncontroller10): used to obtain session IDs, send commands and events to sessions, and obtain the session metadata and playback state information. +- [AVCastController](#avcastcontroller10): used to control playback, listen for remote playback state changes, and obtain the remote playback state in casting scenarios. > **NOTE** > @@ -52,13 +53,15 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js import featureAbility from '@ohos.ability.featureAbility'; -let session; +let currentAVSession; let tag = "createNewSession"; let context = featureAbility.getContext(); +let sessionId; // Used as an input parameter of subsequent functions. -await avSession.createAVSession(context, tag, "audio").then((data) => { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); +avSession.createAVSession(context, tag, "audio").then((data) => { + currentAVSession = data; + sessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); }).catch((err) => { console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); }); @@ -94,16 +97,18 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js import featureAbility from '@ohos.ability.featureAbility'; -let session; +let currentAVSession; let tag = "createNewSession"; let context = featureAbility.getContext(); +let sessionId; // Used as an input parameter of subsequent functions. avSession.createAVSession(context, tag, "audio", function (err, data) { if (err) { console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); } else { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); + currentAVSession = data; + sessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); } }); ``` @@ -145,7 +150,7 @@ avSession.getAllSessionDescriptors().then((descriptors) => { console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); } }).catch((err) => { - console.info(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -180,7 +185,7 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js avSession.getAllSessionDescriptors(function (err, descriptors) { if (err) { - console.info(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`GetAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); if(descriptors.length > 0 ){ @@ -237,7 +242,7 @@ avSession.getHistoricalSessionDescriptors().then((descriptors) => { console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); } }).catch((err) => { - console.info(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -273,7 +278,7 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js avSession.getHistoricalSessionDescriptors(1, function (err, descriptors) { if (err) { - console.info(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); if(descriptors.length > 0 ){ @@ -307,9 +312,9 @@ Creates a session controller based on the session ID. Multiple session controlle **Return value** -| Type | Description | -| ------------------------------------------------------- | ------------------------------------------------------------ | -| Promise<[AVSessionController](#avsessioncontroller10)\> | Promise used to return the session controller created, which can be used to obtain the session ID, send commands and events to sessions, and obtain metadata and playback state information. | +| Type | Description | +| ----------------------------------------------------- | ------------------------------------------------------------ | +| Promise<[AVSessionController](#avsessioncontroller10)\> | Promise used to return the session controller created, which can be used to obtain the session ID, send commands and events to sessions, and obtain metadata and playback state information.| **Error codes** @@ -325,23 +330,27 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js import featureAbility from '@ohos.ability.featureAbility'; -let session; +let currentAVSession; let tag = "createNewSession"; let context = featureAbility.getContext(); +let sessionId; // Used as an input parameter of subsequent functions. -await avSession.createAVSession(context, tag, "audio").then((data) => { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); -}).catch((err) => { - console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + sessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); + } }); -let controller; -await avSession.createController(session.sessionId).then((avcontroller) => { - controller = avcontroller; - console.info(`CreateController : SUCCESS : ${controller.sessionId}`); +let currentAVcontroller; +avSession.createController(sessionId).then((avcontroller) => { + currentAVcontroller = avcontroller; + console.info('CreateController : SUCCESS '); }).catch((err) => { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -378,24 +387,28 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js import featureAbility from '@ohos.ability.featureAbility'; -let session; +let currentAVSession; let tag = "createNewSession"; let context = featureAbility.getContext(); +let sessionId; // Used as an input parameter of subsequent functions. -await avSession.createAVSession(context, tag, "audio").then((data) => { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); -}).catch((err) => { - console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + sessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); + } }); -let controller; -avSession.createController(session.sessionId, function (err, avcontroller) { +let currentAVcontroller; +avSession.createController(sessionId, function (err, avcontroller) { if (err) { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); } else { - controller = avcontroller; - console.info(`CreateController : SUCCESS : ${controller.sessionId}`); + currentAVcontroller = avcontroller; + console.info('CreateController : SUCCESS '); } }); ``` @@ -416,16 +429,16 @@ Before calling this API, import the **ohos.multimedia.audio** module to obtain t **Parameters** -| Name | Type | Mandatory| Description | -| ------------ |--------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---- | ------------------------------------------------------------ | -| session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.| -| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | Yes | Audio devices. | +| Name | Type | Mandatory| Description| +| ------------ | -------------- |------|------| +| session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.| +| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | Yes | Audio devices. | **Return value** | Type | Description | | -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the casting is successful, no value is returned; otherwise, an error object is returned.| +| Promise\ | Promise used to return the result. If casting is successful, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -435,7 +448,7 @@ For details about the error codes, see [AVSession Management Error Codes](../err | -------- | ---------------------------------------- | | 6600101 | Session service exception. | | 6600102 | The session does not exist. | -| 6600104 | The remote session connection failed. | +| 6600104 | The remote session connection failed. | **Example** @@ -449,13 +462,13 @@ await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then( audioDevices = data; console.info(`Promise returned to indicate that the device list is obtained.`); }).catch((err) => { - console.info(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); }); avSession.castAudio('all', audioDevices).then(() => { console.info(`CreateController : SUCCESS`); }).catch((err) => { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -478,8 +491,8 @@ Before calling this API, import the **ohos.multimedia.audio** module to obtain t | Name | Type | Mandatory| Description | | ------------ |--------------------------------------------| ---- | ------------------------------------------------------------ | | session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.| -| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | Yes | Audio devices. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the casting is successful, **err** is **undefined**; otherwise, **err** is an error object. | +| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | Yes | Audio devices.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the casting is successful, **err** is **undefined**; otherwise, **err** is an error object. | **Error codes** @@ -489,7 +502,7 @@ For details about the error codes, see [AVSession Management Error Codes](../err | -------- | ---------------------------------------- | | 6600101 | Session service exception. | | 6600102 | The session does not exist. | -| 6600104 | The remote session connection failed. | +| 6600104 | The remote session connection failed. | **Example** @@ -503,23 +516,39 @@ await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then( audioDevices = data; console.info(`Promise returned to indicate that the device list is obtained.`); }).catch((err) => { - console.info(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); }); avSession.castAudio('all', audioDevices, function (err) { if (err) { - console.info(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`CastAudio : SUCCESS `); } }); ``` -## avSession.on('sessionCreate' | 'sessionDestroy' | 'topSessionChange') +## SessionToken + +Describes the information about a session token. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) + +**System capability**: SystemCapability.Multimedia.AVSession.Manager + +**System API**: This is a system API. + +| Name | Type | Mandatory| Description | +| :-------- | :----- | :--- | :----------- | +| sessionId | string | Yes | Session ID. | +| pid | number | No | Process ID of the session.| +| uid | number | No | User ID. | + +## avSession.on('sessionCreate') -on(type: 'sessionCreate' | 'sessionDestroy' | 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void +on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void -Subscribes to session creation, session destruction, and top session change events. +Subscribes to session creation events. **Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) @@ -529,10 +558,10 @@ Subscribes to session creation, session destruction, and top session change even **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type.
- **'sessionCreate'**: session creation event, which is reported when a session is created.
- **'sessionDestroy'**: session destruction event, which is reported when a session is destroyed.
- **'topSessionChange'**: top session change event, which is reported when the top session is changed.| -| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor. | +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'sessionCreate'** is triggered when a session is created.| +| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor.| **Error codes** @@ -551,12 +580,75 @@ avSession.on('sessionCreate', (descriptor) => { console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`); }); +``` + +## avSession.on('sessionDestroy') + +on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): void + +Subscribes to session destruction events. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) + +**System capability**: SystemCapability.Multimedia.AVSession.Manager + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------| ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.| +| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**Example** + +```js avSession.on('sessionDestroy', (descriptor) => { console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`); console.info(`on sessionDestroy : type : ${descriptor.type}`); console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`); }); +``` + +## avSession.on('topSessionChange') + +on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void + +Subscribes to top session change events. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) +**System capability**: SystemCapability.Multimedia.AVSession.Manager + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------| ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'topSessionChange'** is triggered when the top session is changed.| +| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**Example** + +```js avSession.on('topSessionChange', (descriptor) => { console.info(`on topSessionChange : isActive : ${descriptor.isActive}`); console.info(`on topSessionChange : type : ${descriptor.type}`); @@ -564,11 +656,11 @@ avSession.on('topSessionChange', (descriptor) => { }); ``` -## avSession.off('sessionCreate' | 'sessionDestroy' | 'topSessionChange') +## avSession.off('sessionCreate') -off(type: 'sessionCreate' | 'sessionDestroy' | 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void +off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): void -Unsubscribes from session creation, session destruction, and top session change events. +Unsubscribes from session creation events. **Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) @@ -578,9 +670,9 @@ Unsubscribes from session creation, session destruction, and top session change **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type.
- **'sessionCreate'**: session creation event, which is reported when a session is created.
- **'sessionDestroy'**: session destruction event, which is reported when a session is destroyed.
- **'topSessionChange'**: top session change event, which is reported when the top session is changed.| +| Name | Type | Mandatory| Description | +| -------- | ----------| ---- | ----------| +| type | string | Yes | Event type, which is **'sessionCreate'** in this case.| | callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -595,7 +687,71 @@ For details about the error codes, see [AVSession Management Error Codes](../err ```js avSession.off('sessionCreate'); +``` + +## avSession.off('sessionDestroy') + +off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): void + +Unsubscribes from session destruction events. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) + +**System capability**: SystemCapability.Multimedia.AVSession.Manager + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -----------| ---- | -------------------------| +| type | string | Yes | Event type, which is **'sessionDestroy'** in this case.| +| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**Example** + +```js avSession.off('sessionDestroy'); +``` + +## avSession.off('topSessionChange') + +off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void + +Unsubscribes from top session change events. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) + +**System capability**: SystemCapability.Multimedia.AVSession.Manager + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -----------------| ---- | ---------------------------- | +| type | string | Yes | Event type, which is **'topSessionChange'** in this case.| +| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**Example** + +```js avSession.off('topSessionChange'); ``` @@ -613,7 +769,7 @@ Subscribes to session service death events. | Name | Type | Mandatory| Description | | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'sessionServiceDie'** is reported when the session service dies.| +| type | string | Yes | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.| | callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | **Error codes** @@ -646,7 +802,7 @@ Unsubscribes from session service death events. | Name | Type | Mandatory | Description | | ------ | ---------------------- | ---- | ------------------------------------------------------- | -| type | string | Yes | Event type. The event **'sessionServiceDie'** is reported when the session service dies.| +| type | string | Yes | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.| | callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -665,9 +821,9 @@ avSession.off('sessionServiceDie'); ## avSession.sendSystemAVKeyEvent -sendSystemAVKeyEvent(event: KeyEvent): Promise\ +sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void -Sends a system key event to the top session. This API uses a promise to return the result. +Sends a system key event to the top session. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) @@ -677,15 +833,10 @@ Sends a system key event to the top session. This API uses a promise to return t **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------------------------------- | ---- | ---------- | -| event | [KeyEvent](js-apis-keyevent.md) | Yes | Key event.| - -**Return value** - -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- | +| event | [KeyEvent](js-apis-keyevent.md) | Yes | Key event. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -699,23 +850,23 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js - let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let event = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; -avSession.sendSystemAVKeyEvent(event).then(() => { - console.info(`SendSystemAVKeyEvent Successfully`); -}).catch((err) => { - console.info(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); +avSession.sendSystemAVKeyEvent(event, function (err) { + if (err) { + console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SendSystemAVKeyEvent : SUCCESS `); + } }); - ``` ## avSession.sendSystemAVKeyEvent -sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void +sendSystemAVKeyEvent(event: KeyEvent): Promise\ -Sends a system key event to the top session. This API uses an asynchronous callback to return the result. +Sends a system key event to the top session. This API uses a promise to return the result. **Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) @@ -725,10 +876,15 @@ Sends a system key event to the top session. This API uses an asynchronous callb **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- | -| event | [KeyEvent](js-apis-keyevent.md) | Yes | Key event. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.| +| Name| Type | Mandatory| Description | +| ------ | ------------------------------- | ---- | ---------- | +| event | [KeyEvent](js-apis-keyevent.md) | Yes | Key event.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -742,23 +898,22 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js + let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let event = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; -avSession.sendSystemAVKeyEvent(event, function (err) { - if (err) { - console.info(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SendSystemAVKeyEvent : SUCCESS `); - } +avSession.sendSystemAVKeyEvent(event).then(() => { + console.info(`SendSystemAVKeyEvent Successfully`); +}).catch((err) => { + console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` ## avSession.sendSystemControlCommand -sendSystemControlCommand(command: AVControlCommand): Promise\ +sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\): void -Sends a system control command to the top session. This API uses a promise to return the result. +Sends a system control command to the top session. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) @@ -768,15 +923,10 @@ Sends a system control command to the top session. This API uses a promise to re **Parameters** -| Name | Type | Mandatory| Description | -| ------- | ------------------------------------- | ---- | ----------------------------------- | -| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send.| - -**Return value** - -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -807,18 +957,20 @@ let avcommand = {command:cmd}; // let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let cmd : avSession.AVControlCommandType = 'toggleFavorite'; // let avcommand = {command:cmd, parameter:"false"}; -avSession.sendSystemControlCommand(avcommand).then(() => { - console.info(`SendSystemControlCommand successfully`); -}).catch((err) => { - console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); +avSession.sendSystemControlCommand(avcommand, function (err) { + if (err) { + console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`sendSystemControlCommand successfully`); + } }); ``` ## avSession.sendSystemControlCommand -sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\): void +sendSystemControlCommand(command: AVControlCommand): Promise\ -Sends a system control command to the top session. This API uses an asynchronous callback to return the result. +Sends a system control command to the top session. This API uses a promise to return the result. **Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) @@ -828,10 +980,15 @@ Sends a system control command to the top session. This API uses an asynchronous **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------- | ---- | ------------------------------------- | -| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------- | ---- | ----------------------------------- | +| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -862,52 +1019,2433 @@ let avcommand = {command:cmd}; // let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let cmd : avSession.AVControlCommandType = 'toggleFavorite'; // let avcommand = {command:cmd, parameter:"false"}; -avSession.sendSystemControlCommand(avcommand, function (err) { - if (err) { - console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`sendSystemControlCommand successfully`); - } +avSession.sendSystemControlCommand(avcommand).then(() => { + console.info(`SendSystemControlCommand successfully`); +}).catch((err) => { + console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -## AVSession10+ +## ProtocolType10+ -An **AVSession** object is created by calling [avSession.createAVSession](#avsessioncreateavsession10). The object enables you to obtain the session ID and set the metadata and playback state. +Enumerates the protocol types supported by the remote device. -### Attributes +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System API**: This is a system API. -| Name | Type | Readable| Writable| Description | -| :-------- | :----- | :--- | :--- | :---------------------------- | -| sessionId | string | Yes | No | Unique session ID of the **AVSession** object.| +| Name | Value | Description | +| --------------------------- | ---- | ----------- | +| TYPE_LOCAL | 0 | Local device. | +| TYPE_CAST_PLUS_MIRROR | 1 | Cast+ mirror mode.| +| TYPE_CAST_PLUS_STREAM | 2 | Cast+ stream mode.| +## avSession.startCastDeviceDiscovery10+ -**Example** -```js -let sessionId = session.sessionId; -``` +startCastDeviceDiscovery(callback: AsyncCallback\): void -### setAVMetadata10+ +Starts cast-enabled device discovery. This API uses an asynchronous callback to return the result. -setAVMetadata(data: AVMetadata): Promise\ +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -Sets session metadata. This API uses a promise to return the result. +**System API**: This is a system API. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent and device discovery starts, **err** is **undefined**; otherwise, **err** is an error object.| + + +**Example** + +```js +avSession.startCastDeviceDiscovery(function (err) { + if (err) { + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`startCastDeviceDiscovery successfully`); + } +}); +``` + +## avSession.startCastDeviceDiscovery10+ + +startCastDeviceDiscovery(filter: number, callback: AsyncCallback\): void + +Starts cast-enabled device discovery with filter criteria specified. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| filter | number | Yes| Filter criteria for device discovery. The value consists of **ProtocolType**s.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent and device discovery starts, **err** is **undefined**; otherwise, **err** is an error object.| + + +**Example** + +```js +let filter = 2; +avSession.startCastDeviceDiscovery(filter, function (err) { + if (err) { + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`startCastDeviceDiscovery successfully`); + } +}); +``` + +## avSession.startCastDeviceDiscovery10+ + +startCastDeviceDiscovery(filter?: number): Promise\ + +Starts cast-enabled device discovery. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| filter | number | No| Filter criteria for device discovery. The value consists of **ProtocolType**s.| + +**Return value** +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the command is sent and device discovery starts, no value is returned; otherwise, an error object is returned.| + +**Example** + +```js +let filter = 2; +avSession.startCastDeviceDiscovery(filter).then(() => { + console.info(`startCastDeviceDiscovery successfully`); +}).catch((err) => { + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +## avSession.stopCastDeviceDiscovery10+ + +stopCastDeviceDiscovery(callback: AsyncCallback\): void + +Stops cast-enabled device discovery. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If device discovery stops, **err** is **undefined**; otherwise, **err** is an error object.| + + +**Example** + +```js +avSession.stopCastDeviceDiscovery(function (err) { + if (err) { + console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`stopCastDeviceDiscovery successfully`); + } +}); +``` + +## avSession.stopCastDeviceDiscovery10+ + +stopCastDeviceDiscovery(): Promise\ + +Stops cast-enabled device discovery. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If device discovery stops, no value is returned; otherwise, an error object is returned.| + +**Example** + +```js +avSession.stopCastDeviceDiscovery().then(() => { + console.info(`startCastDeviceDiscovery successfully`); +}).catch((err) => { + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +## avSession.setDiscoverable10+ + +setDiscoverable(enable: boolean, callback: AsyncCallback\): void + +Sets whether to allow the device discoverable. A discoverable device can be used as the cast receiver. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| enable | boolean | Yes| Whether to allow the device discoverable. The value **true** means to allow the device discoverable, and **false** means the opposite.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + + +**Example** + +```js +avSession.setDiscoverable(true, function (err) { + if (err) { + console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`setDiscoverable successfully`); + } +}); +``` + +## avSession.setDiscoverable10+ + +setDiscoverable(enable: boolean): Promise\ + +Sets whether to allow the device discoverable. A discoverable device can be used as the cast receiver. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| enable | boolean | Yes| Whether to allow the device discoverable. The value **true** means to allow the device discoverable, and **false** means the opposite.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Example** + +```js +avSession.setDiscoverable(true).then(() => { + console.info(`setDiscoverable successfully`); +}).catch((err) => { + console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +## avSession.on('deviceAvailable')10+ + +on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void + +Subscribes to device discovery events. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.| +| callback | (device: OutputDeviceInfo) => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**Example** + +```js +let castDevice; +avSession.on('deviceAvailable', (device) => { + castDevice = device; + console.info(`on deviceAvailable : ${device} `); +}); +``` + +## avSession.off('deviceAvailable')10+ + +off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void + +Unsubscribes from device discovery events. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------ | ---------------------- | ---- | ------------------------------------------------------- | +| type | string | Yes | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**Example** + +```js +avSession.off('deviceAvailable'); +``` + +## avSession.getAVCastController10+ + +getAVCastController(sessionId: string, callback: AsyncCallback\): void + +Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| sessionId | string | Yes |Session ID.| +| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes | Callback used to return the cast controller.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception | +| 6600102 | session does not exist | + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility'; + +let currentAVSession; +let tag = "createNewSession"; +let context = featureAbility.getContext(); +let sessionId; // Used as an input parameter of subsequent functions. + +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + sessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); + } +}); + +let aVCastController; +avSession.getAVCastController(sessionId ,function (err, avcontroller) { + if (err) { + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + aVCastController = avcontroller; + console.info('getAVCastController : SUCCESS '); + } +}); +``` + +## avSession.getAVCastController10+ + +getAVCastController(sessionId: string): Promise\; + +Obtains the cast controller when a casting connection is set up. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ------------------------- | ---- | ------------------------------------------------------------ | +| sessionId | string | Yes |Session ID.| + +**Return value** + +| Type | Description | +| --------- | ------------------------------------------------------------ | +| Promise<[AVCastController](#avcastcontroller10)\> | Promise used to return the cast controller.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | server exception | +| 6600102 | The session does not exist | + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility'; + +let currentAVSession; +let tag = "createNewSession"; +let context = featureAbility.getContext(); +let sessionId; // Used as an input parameter of subsequent functions. + +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + sessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); + } +}); + +let aVCastController; +avSession.getAVCastController(sessionId).then((avcontroller) => { + aVCastController = avcontroller; + console.info('getAVCastController : SUCCESS'); +}).catch((err) => { + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +## avSession.startCasting10+ + +startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\): void + +Starts casting. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| session | [SessionToken](#sessiontoken) | Yes | Session token. | +| device | [OutputDeviceInfo](#outputdeviceinfo10) | Yes | Device-related information.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent and casting starts, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600108 | Device connecting failed. | + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility'; + +let currentAVSession; +let tag = "createNewSession"; +let context = featureAbility.getContext(); +let currSessionId; // Used as an input parameter of subsequent functions. + +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + currSessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); + } +}); + +let myToken = { + sessionId: currSessionId, +} +let castDevice; +avSession.on('deviceAvailable', (device) => { + castDevice = device; + console.info(`on deviceAvailable : ${device} `); +}); +avSession.startCasting(myToken, castDevice, function (err) { + if (err) { + console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`startCasting successfully`); + } +}); +``` + +## avSession.startCasting10+ + +startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\ + +Starts casting. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| session | [SessionToken](#sessiontoken) | Yes | Session token. | +| device | [OutputDeviceInfo](#outputdeviceinfo10) | Yes | Device-related information.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the command is sent and casting starts, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600108 | Device connecting failed. | + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility'; + +let currentAVSession; +let tag = "createNewSession"; +let context = featureAbility.getContext(); +let currSessionId; // Used as an input parameter of subsequent functions. + +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + currSessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); + } +}); + +let myToken = { + sessionId: currSessionId, +} +let castDevice; +avSession.on('deviceAvailable', (device) => { + castDevice = device; + console.info(`on deviceAvailable : ${device} `); +}); +avSession.startCasting(myToken, castDevice).then(() => { + console.info(`startCasting successfully`); +}).catch((err) => { + console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +## avSession.stopCasting10+ + +stopCasting(session: SessionToken, callback: AsyncCallback\): void + +Stops castings. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| session | [SessionToken](#sessiontoken) | Yes | Session token. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If casting stops, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600109 | The remote connection is not established. | + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility'; + +let currentAVSession; +let tag = "createNewSession"; +let context = featureAbility.getContext(); +let currSessionId; // Used as an input parameter of subsequent functions. + +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + currSessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); + } +}); + +let myToken = { + sessionId: currSessionId, +} +avSession.stopCasting(myToken, function (err) { + if (err) { + console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`stopCasting successfully`); + } +}); +``` + +## avSession.stopCasting10+ + +stopCasting(session: SessionToken): Promise\ + +Stops castings. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| session | [SessionToken](#sessiontoken) | Yes | Session token. | + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600109 | The remote connection is not established. | + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility'; + +let currentAVSession; +let tag = "createNewSession"; +let context = featureAbility.getContext(); +let currSessionId; // Used as an input parameter of subsequent functions. + +avSession.createAVSession(context, tag, "audio", function (err, data) { + if (err) { + console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + currentAVSession = data; + currSessionId = currentAVSession.sessionId; + console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); + } +}); + +let myToken = { + sessionId: currSessionId, +} +avSession.stopCasting(myToken).then(() => { + console.info(`stopCasting successfully`); +}).catch((err) => { + console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +## AVSessionType10+ +Enumerates the session types supported by the session. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +| Name | Type | Description| +| ----- | ------ | ---- | +| audio | string | Audio session.| +| video | string | Video session.| + +## AVSession10+ + +An **AVSession** object is created by calling [avSession.createAVSession](#avsessioncreateavsession10). The object enables you to obtain the session ID and set the metadata and playback state. + +### Attributes + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +| Name | Type | Readable| Writable| Description | +| :-------- | :----- | :--- | :--- | :---------------------------- | +| sessionId | string | Yes | No | Unique session ID of the **AVSession** object.| +| sessionType10+ | AVSessionType | Yes | No | AVSession type.| + + +**Example** +```js +let sessionId = currentAVSession.sessionId; +let sessionType = currentAVSession.sessionType; +``` + +### setAVMetadata10+ + +setAVMetadata(data: AVMetadata): Promise\ + +Sets session metadata. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------------------------- | ---- | ------------ | +| data | [AVMetadata](#avmetadata10) | Yes | Session metadata.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let metadata = { + assetId: "121278", + title: "lose yourself", + artist: "Eminem", + author: "ST", + album: "Slim shady", + writer: "ST", + composer: "ST", + duration: 2222, + mediaImage: "https://www.example.com/example.jpg", + subtitle: "8 Mile", + description: "Rap", + lyric: "https://www.example.com/example.lrc", + previousAssetId: "121277", + nextAssetId: "121279", +}; +currentAVSession.setAVMetadata(metadata).then(() => { + console.info(`SetAVMetadata successfully`); +}).catch((err) => { + console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### setAVMetadata10+ + +setAVMetadata(data: AVMetadata, callback: AsyncCallback\): void + +Sets session metadata. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| data | [AVMetadata](#avmetadata10) | Yes | Session metadata. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let metadata = { + assetId: "121278", + title: "lose yourself", + artist: "Eminem", + author: "ST", + album: "Slim shady", + writer: "ST", + composer: "ST", + duration: 2222, + mediaImage: "https://www.example.com/example.jpg", + subtitle: "8 Mile", + description: "Rap", + lyric: "https://www.example.com/example.lrc", + previousAssetId: "121277", + nextAssetId: "121279", +}; +currentAVSession.setAVMetadata(metadata, function (err) { + if (err) { + console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SetAVMetadata successfully`); + } +}); +``` + +### setAVPlaybackState10+ + +setAVPlaybackState(state: AVPlaybackState): Promise\ + +Sets information related to the session playback state. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ----------------------------------- | ---- | ---------------------------------------------- | +| data | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let playbackState = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: 1.0, + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + bufferedTime:1000, + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite:true, +}; +currentAVSession.setAVPlaybackState(playbackState).then(() => { + console.info(`SetAVPlaybackState successfully`); +}).catch((err) => { + console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### setAVPlaybackState10+ + +setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\): void + +Sets information related to the session playback state. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------- | ---- | ---------------------------------------------- | +| data | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let PlaybackState = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: 1.0, + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + bufferedTime:1000, + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite:true, +}; +currentAVSession.setAVPlaybackState(PlaybackState, function (err) { + if (err) { + console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SetAVPlaybackState successfully`); + } +}); +``` + +### setLaunchAbility10+ + +setLaunchAbility(ability: WantAgent): Promise\ + +Sets a launcher ability. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Application attributes, such as the bundle name, ability name, and deviceID.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +import wantAgent from '@ohos.app.ability.wantAgent'; + +// WantAgentInfo object +let wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.example.myapplication", + abilityName: "EntryAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: wantAgent.OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +wantAgent.getWantAgent(wantAgentInfo).then((agent) => { + currentAVSession.setLaunchAbility(agent).then(() => { + console.info(`SetLaunchAbility successfully`); + }).catch((err) => { + console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + }); +}); +``` + +### setLaunchAbility10+ + +setLaunchAbility(ability: WantAgent, callback: AsyncCallback\): void + +Sets a launcher ability. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | +| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Application attributes, such as the bundle name, ability name, and deviceID. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +import wantAgent from '@ohos.app.ability.wantAgent'; + +// WantAgentInfo object +let wantAgentInfo = { + wants: [ + { + deviceId: "deviceId", + bundleName: "com.example.myapplication", + abilityName: "EntryAbility", + action: "action1", + entities: ["entity1"], + type: "MIMETYPE", + uri: "key={true,true,false}", + parameters: + { + mykey0: 2222, + mykey1: [1, 2, 3], + mykey2: "[1, 2, 3]", + mykey3: "ssssssssssssssssssssssssss", + mykey4: [false, true, false], + mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], + mykey6: true, + } + } + ], + operationType: wantAgent.OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] +} + +wantAgent.getWantAgent(wantAgentInfo).then((agent) => { + currentAVSession.setLaunchAbility(agent, function (err) { + if (err) { + console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SetLaunchAbility successfully`); + } + }); +}); +``` + +### dispatchSessionEvent10+ + +dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\ + +Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses a promise to return the result. It is called by the provider. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| event | string | Yes | Name of the session event.| +| args | {[key: string]: any} | Yes | Event content in key-value pair format.| + +> **NOTE** +> +> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md). + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let eventName = "dynamic_lyric"; +let args = { + lyric : "This is lyric" +} +currentAVSession.dispatchSessionEvent(eventName, args).catch((err) => { + console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); +}) +``` + +### dispatchSessionEvent10+ + +dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\): void + +Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses an asynchronous callback to return the result. It is called by the provider. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| event | string | Yes | Name of the session event.| +| args | {[key: string]: any} | Yes | Event content in key-value pair format.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +> **NOTE** +> +> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md). + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let eventName = "dynamic_lyric"; +let args = { + lyric : "This is lyric" +} +currentAVSession.dispatchSessionEvent(eventName, args, (err) => { + if(err) { + console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); + } +}) +``` + +### setAVQueueItems10+ + +setAVQueueItems(items: Array\): Promise\ + +Sets a playlist. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------------------------------------ | ---- | ---------------------------------- | +| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +import image from '@ohos.multimedia.image'; +import resourceManager from '@ohos.resourceManager'; + +let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); +let imageSource : imageImageSource = image.createImageSource(value.buffer); +let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); +let queueItemDescription_1 = { + mediaId: '001', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon : imagePixel, + iconUri: 'http://www.icon.uri.com', + extras: {'extras':'any'} +}; +let queueItem_1 = { + itemId: 1, + description: queueItemDescription_1 +}; +let queueItemDescription_2 = { + mediaId: '002', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon: imagePixel, + iconUri: 'http://www.xxx.com', + extras: {'extras':'any'} +}; +let queueItem_2 = { + itemId: 2, + description: queueItemDescription_2 +}; +let queueItemsArray = [queueItem_1, queueItem_2]; +currentAVSession.setAVQueueItems(queueItemsArray).then(() => { + console.info(`SetAVQueueItems successfully`); +}).catch((err) => { + console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### setAVQueueItems10+ + +setAVQueueItems(items: Array\, callback: AsyncCallback\): void + +Sets a playlist. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | +| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +import image from '@ohos.multimedia.image'; +import resourceManager from '@ohos.resourceManager'; + +let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); +let imageSource : imageImageSource = image.createImageSource(value.buffer); +let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); +let queueItemDescription_1 = { + mediaId: '001', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon: imagePixel, + iconUri: 'http://www.icon.uri.com', + extras: {'extras':'any'} +}; +let queueItem_1 = { + itemId: 1, + description: queueItemDescription_1 +}; +let queueItemDescription_2 = { + mediaId: '002', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon: imagePixel, + iconUri: 'http://www.icon.uri.com', + extras: {'extras':'any'} +}; +let queueItem_2 = { + itemId: 2, + description: queueItemDescription_2 +}; +let queueItemsArray = [queueItem_1, queueItem_2]; +currentAVSession.setAVQueueItems(queueItemsArray, function (err) { + if (err) { + console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SetAVQueueItems successfully`); + } +}); +``` + +### setAVQueueTitle10+ + +setAVQueueTitle(title: string): Promise\ + +Sets a name for the playlist. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------ | ------ | ---- | -------------- | +| title | string | Yes | Name of the playlist.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let queueTitle = 'QUEUE_TITLE'; +currentAVSession.setAVQueueTitle(queueTitle).then(() => { + console.info(`SetAVQueueTitle successfully`); +}).catch((err) => { + console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### setAVQueueTitle10+ + +setAVQueueTitle(title: string, callback: AsyncCallback\): void + +Sets a name for the playlist. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ----------------------------------------------------------- | +| title | string | Yes | Name of the playlist. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let queueTitle = 'QUEUE_TITLE'; +currentAVSession.setAVQueueTitle(queueTitle, function (err) { + if (err) { + console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.error(`SetAVQueueTitle successfully`); + } +}); +``` + +### setExtras10+ + +setExtras(extras: {[key: string]: Object}): Promise\ + +Sets a custom media packet in the form of key-value pairs. This API uses a promise to return the result. It is called by the provider. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| extras | {[key: string]: Object} | Yes | Key-value pairs of the custom media packet.| + +> **NOTE** +> +> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md). + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let extras = { + extras : "This is custom media packet" +} +currentAVSession.setExtras(extras).catch((err) => { + console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); +}) +``` + +### setExtras10+ + +setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\): void + +Sets a custom media packet in the form of key-value pairs. This API uses an asynchronous callback to return the result. It is called by the provider. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| extras | {[key: string]: any} | Yes | Key-value pairs of the custom media packet.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| + +> **NOTE** +> +> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md). + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let extras = { + extras : "This is custom media packet" +} +currentAVSession.setExtras(extras, (err) => { + if(err) { + console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); + } +}) +``` + +### getController10+ + +getController(): Promise\ + +Obtains the controller corresponding to this session. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Return value** + +| Type | Description | +| ---------------------------------------------------- | ----------------------------- | +| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let avsessionController; +currentAVSession.getController().then((avcontroller) => { + avsessionController = avcontroller; + console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); +}).catch((err) => { + console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### getController10+ + +getController(callback: AsyncCallback\): void + +Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes | Callback used to return the session controller.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +let avsessionController; +currentAVSession.getController(function (err, avcontroller) { + if (err) { + console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + avsessionController = avcontroller; + console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); + } +}); +``` + +### getAVCastController10+ + +getAVCastController(callback: AsyncCallback\): void + +Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**Parameters** + +| Name | Type | Mandatory| Description | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes | Callback used to return the cast controller.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600102 | The session does not exist. | +| 6600110 | The remote connection is not established. | + +**Example** + +```js +let aVCastController; +currentAVSession.getAVCastController().then((avcontroller) => { + aVCastController = avcontroller; + console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`); +}).catch((err) => { + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### getAVCastController10+ + +getAVCastController(): Promise\; + +Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**Return value** + +| Type | Description | +| --------- | ------------------------------------------------------------ | +| Promise<[AVCastController](#avcastcontroller10)\> | Promise used to return the cast controller.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600102 | The session does not exist. | +| 6600110 | The remote connection is not established. | + +**Example** + +```js +let aVCastController; +currentAVSession.getAVCastController(function (err, avcontroller) { + if (err) { + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + aVCastController = avcontroller; + console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`); + } +}); +``` + +### getOutputDevice10+ + +getOutputDevice(): Promise\ + +Obtains information about the output device for this session. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Return value** + +| Type | Description | +| ---------------------------------------------- | --------------------------------- | +| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.getOutputDevice().then((outputDeviceInfo) => { + console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); +}).catch((err) => { + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### getOutputDevice10+ + +getOutputDevice(callback: AsyncCallback\): void + +Obtains information about the output device for this session. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | ------------------------------ | +| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.getOutputDevice(function (err, outputDeviceInfo) { + if (err) { + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); + } +}); +``` + +### activate10+ + +activate(): Promise\ + +Activates this session. A session can be used only after being activated. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.activate().then(() => { + console.info(`Activate : SUCCESS `); +}).catch((err) => { + console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### activate10+ + +activate(callback: AsyncCallback\): void + +Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.activate(function (err) { + if (err) { + console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`Activate : SUCCESS `); + } +}); +``` + +### deactivate10+ + +deactivate(): Promise\ + +Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.deactivate().then(() => { + console.info(`Deactivate : SUCCESS `); +}).catch((err) => { + console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### deactivate10+ + +deactivate(callback: AsyncCallback\): void + +Deactivates this session. This API uses an asynchronous callback to return the result. + +Deactivates this session. You can use [activate](#activate10) to activate the session again. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.deactivate(function (err) { + if (err) { + console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`Deactivate : SUCCESS `); + } +}); +``` + +### destroy10+ + +destroy(): Promise\ + +Destroys this session. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.destroy().then(() => { + console.info(`Destroy : SUCCESS `); +}).catch((err) => { + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### destroy10+ + +destroy(callback: AsyncCallback\): void + +Destroys this session. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.destroy(function (err) { + if (err) { + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`Destroy : SUCCESS `); + } +}); +``` + +### on('play')10+ + +on(type: 'play', callback: () => void): void + +Subscribes to playback started events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('play', () => { + console.info(`on play entry`); +}); +``` + +### on('pause')10+ + +on(type: 'pause', callback: () => void): void + +Subscribes to playback paused events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('pause', () => { + console.info(`on pause entry`); +}); +``` + +### on('stop')10+ + +on(type:'stop', callback: () => void): void + +Subscribes to playback stopped events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('stop', () => { + console.info(`on stop entry`); +}); +``` + +### on('playNext')10+ + +on(type:'playNext', callback: () => void): void + +Subscribes to playNext command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('playNext', () => { + console.info(`on playNext entry`); +}); +``` + +### on('playPrevious')10+ + +on(type:'playPrevious', callback: () => void): void + +Subscribes to playPrevious command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('playPrevious', () => { + console.info(`on playPrevious entry`); +}); +``` + +### on('fastForward')10+ + +on(type: 'fastForward', callback: () => void): void + +Subscribes to fastForward command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('fastForward', () => { + console.info(`on fastForward entry`); +}); +``` + +### on('rewind')10+ + +on(type:'rewind', callback: () => void): void + +Subscribes to rewind command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.| +| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('rewind', () => { + console.info(`on rewind entry`); +}); +``` + +### on('seek')10+ + +on(type: 'seek', callback: (time: number) => void): void + +Subscribes to seek command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'seek'** is triggered when the seek command is sent to the session.| +| callback | (time: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('seek', (time) => { + console.info(`on seek entry time : ${time}`); +}); +``` + +### on('setSpeed')10+ + +on(type: 'setSpeed', callback: (speed: number) => void): void + +Subscribes to setSpeed command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.| +| callback | (speed: number) => void | Yes | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('setSpeed', (speed) => { + console.info(`on setSpeed speed : ${speed}`); +}); +``` + +### on('setLoopMode')10+ + +on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void + +Subscribes to setLoopMode command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ---- | +| type | string | Yes | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.| +| callback | (mode: [LoopMode](#loopmode10)) => void | Yes | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('setLoopMode', (mode) => { + console.info(`on setLoopMode mode : ${mode}`); +}); +``` + +### on('toggleFavorite')10+ + +on(type: 'toggleFavorite', callback: (assetId: string) => void): void + +Subscribes to toggleFavorite command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.| +| callback | (assetId: string) => void | Yes | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('toggleFavorite', (assetId) => { + console.info(`on toggleFavorite mode : ${assetId}`); +}); +``` + +### on('skipToQueueItem')10+ + +on(type: 'skipToQueueItem', callback: (itemId: number) => void): void + +Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- | +| type | string | Yes | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.| +| callback | (itemId: number) => void | Yes | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('skipToQueueItem', (itemId) => { + console.info(`on skipToQueueItem id : ${itemId}`); +}); +``` + +### on('handleKeyEvent')10+ + +on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void + +Subscribes to key events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.| +| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | Yes | Callback used for subscription. The **event** parameter in the callback indicates the key event. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('handleKeyEvent', (event) => { + console.info(`on handleKeyEvent event : ${event}`); +}); +``` + +### on('outputDeviceChange')10+ + +on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void + +Subscribes to output device change events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.| +| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback used for subscription. The **device** parameter in the callback indicates the output device information.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | + +**Error codes** +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('outputDeviceChange', (state, device) => { + console.info(`on outputDeviceChange device : ${device}`); +}); +``` + +### on('commonCommand')10+ + +on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void + +Subscribes to custom control command change events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'commonCommand'** is triggered when a custom control command changes.| +| callback | (commonCommand: string, args: {[key:string]: Object}) => void | Yes | Callback used for subscription. The **commonCommand** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command. The parameters must be the same as those set in **sendCommand**. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.on('commonCommand', (commonCommand, args) => { + console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); +}); +``` + +### off('play')10+ + +off(type: 'play', callback?: () => void): void + +Unsubscribes from playback started events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'play'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | + +**Error codes** +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.off('play'); +``` + +### off('pause')10+ + +off(type: 'pause', callback?: () => void): void + +Unsubscribes from playback paused events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'pause'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.off('pause'); +``` + +### off('stop')10+ + +off(type: 'stop', callback?: () => void): void + +Unsubscribes from playback stopped events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'stop'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). -**Parameters** +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | -| Name| Type | Mandatory| Description | -| ------ | ------------------------- | ---- | ------------ | -| data | [AVMetadata](#avmetadata10) | Yes | Session metadata.| +**Example** -**Return value** +```js +currentAVSession.off('stop'); +``` -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +### off('playNext')10+ + +off(type: 'playNext', callback?: () => void): void + +Unsubscribes from playNext command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'playNext'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -921,43 +3459,23 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let metadata = { - assetId: "121278", - title: "lose yourself", - artist: "Eminem", - author: "ST", - album: "Slim shady", - writer: "ST", - composer: "ST", - duration: 2222, - mediaImage: "https://www.example.com/example.jpg", - subtitle: "8 Mile", - description: "Rap", - lyric: "https://www.example.com/example.lrc", - previousAssetId: "121277", - nextAssetId: "121279", -}; -session.setAVMetadata(metadata).then(() => { - console.info(`SetAVMetadata successfully`); -}).catch((err) => { - console.info(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); -}); +currentAVSession.off('playNext'); ``` -### setAVMetadata10+ +### off('playPrevious')10+ -setAVMetadata(data: AVMetadata, callback: AsyncCallback\): void +off(type: 'playPrevious', callback?: () => void): void -Sets session metadata. This API uses an asynchronous callback to return the result. +Unsubscribes from playPrevious command events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ------------------------------------- | -| data | [AVMetadata](#avmetadata10) | Yes | Session metadata. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'playPrevious'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -971,50 +3489,53 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let metadata = { - assetId: "121278", - title: "lose yourself", - artist: "Eminem", - author: "ST", - album: "Slim shady", - writer: "ST", - composer: "ST", - duration: 2222, - mediaImage: "https://www.example.com/example.jpg", - subtitle: "8 Mile", - description: "Rap", - lyric: "https://www.example.com/example.lrc", - previousAssetId: "121277", - nextAssetId: "121279", -}; -session.setAVMetadata(metadata, function (err) { - if (err) { - console.info(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetAVMetadata successfully`); - } -}); +currentAVSession.off('playPrevious'); ``` -### setAVPlaybackState10+ +### off('fastForward')10+ -setAVPlaybackState(state: AVPlaybackState): Promise\ +off(type: 'fastForward', callback?: () => void): void -Sets information related to the session playback state. This API uses a promise to return the result. +Unsubscribes from fastForward command events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ----------------------------------- | ---- | ---------------------------------------------- | -| data | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'fastForward'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | -**Return value** +**Error codes** -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.off('fastForward'); +``` + +### off('rewind')10+ + +off(type: 'rewind', callback?: () => void): void + +Unsubscribes from rewind command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'rewind'** in this case.| +| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -1028,35 +3549,23 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let playbackState = { - state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, - speed: 1.0, - position:{elapsedTime:10, updateTime:(new Date()).getTime()}, - bufferedTime:1000, - loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, - isFavorite:true, -}; -session.setAVPlaybackState(playbackState).then(() => { - console.info(`SetAVPlaybackState successfully`); -}).catch((err) => { - console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); -}); +currentAVSession.off('rewind'); ``` -### setAVPlaybackState10+ +### off('seek')10+ -setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\): void +off(type: 'seek', callback?: (time: number) => void): void -Sets information related to the session playback state. This API uses an asynchronous callback to return the result. +Unsubscribes from seek command events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------- | ---- | ---------------------------------------------- | -| data | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. | +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ----------------------------------------- | +| type | string | Yes | Event type, which is **'seek'** in this case. | +| callback | (time: number) => void | No | Callback used for unsubscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -1070,42 +3579,53 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let PlaybackState = { - state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, - speed: 1.0, - position:{elapsedTime:10, updateTime:(new Date()).getTime()}, - bufferedTime:1000, - loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, - isFavorite:true, -}; -session.setAVPlaybackState(PlaybackState, function (err) { - if (err) { - console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetAVPlaybackState successfully`); - } -}); +currentAVSession.off('seek'); ``` -### setAVQueueItems10+ +### off('setSpeed')10+ -setAVQueueItems(items: Array\): Promise\ +off(type: 'setSpeed', callback?: (speed: number) => void): void -Sets a playlist. This API uses a promise to return the result. +Unsubscribes from setSpeed command events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------ | ------------------------------------ | ---- | ---------------------------------- | -| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------------| +| type | string | Yes | Event type, which is **'setSpeed'** in this case. | +| callback | (speed: number) => void | No | Callback used for unsubscription. The **speed** parameter in the callback indicates the playback speed.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | -**Return value** +**Error codes** -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.off('setSpeed'); +``` + +### off('setLoopMode')10+ + +off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void + +Unsubscribes from setSpeed command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ----- | +| type | string | Yes | Event type, which is **'setLoopMode'** in this case.| +| callback | (mode: [LoopMode](#loopmode10)) => void | No | Callback used for unsubscription. The **mode** parameter in the callback indicates the loop mode.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| **Error codes** @@ -1119,60 +3639,53 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -import image from '@ohos.multimedia.image'; -import resourceManager from '@ohos.resourceManager'; +currentAVSession.off('setLoopMode'); +``` -let value : Uint8Array = await resourceManager.getRawFile('IMAGE_URI'); -let imageSource : imageImageSource = image.createImageSource(value.buffer); -let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); -let queueItemDescription_1 = { - mediaId: '001', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon : imagePixel, - iconUri: 'http://www.icon.uri.com', - extras: {'extras':'any'} -}; -let queueItem_1 = { - itemId: 1, - description: queueItemDescription_1 -}; -let queueItemDescription_2 = { - mediaId: '002', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon: imagePixel, - iconUri: 'http://www.xxx.com', - extras: {'extras':'any'} -}; -let queueItem_2 = { - itemId: 2, - description: queueItemDescription_2 -}; -let queueItemsArray = [queueItem_1, queueItem_2]; -session.setAVQueueItems(queueItemsArray).then(() => { - console.info(`SetAVQueueItems successfully`); -}).catch((err) => { - console.info(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); -}); +### off('toggleFavorite')10+ + +off(type: 'toggleFavorite', callback?: (assetId: string) => void): void + +Unsubscribes from toggleFavorite command events. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------------------------------------- | +| type | string | Yes | Event type, which is **'toggleFavorite'** in this case. | +| callback | (assetId: string) => void | No | Callback used for unsubscription. The **assetId** parameter in the callback indicates the media asset ID.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**Example** + +```js +currentAVSession.off('toggleFavorite'); ``` -### setAVQueueItems10+ +### off('skipToQueueItem')10+ -setAVQueueItems(items: Array\, callback: AsyncCallback\): void +off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void -Sets a playlist. This API uses an asynchronous callback to return the result. +Unsubscribes from the event that indicates an item in the playlist is selected. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | -| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'skipToQueueItem'** in this case. | +| callback | (itemId: number) => void | No | Callback used for unsubscription. The **itemId** parameter in the callback indicates the ID of the item.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| **Error codes** @@ -1186,67 +3699,23 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -import image from '@ohos.multimedia.image'; -import resourceManager from '@ohos.resourceManager'; - -let value : Uint8Array = await resourceManager.getRawFile('IMAGE_URI'); -let imageSource : imageImageSource = image.createImageSource(value.buffer); -let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); -let queueItemDescription_1 = { - mediaId: '001', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon: imagePixel, - iconUri: 'http://www.icon.uri.com', - extras: {'extras':'any'} -}; -let queueItem_1 = { - itemId: 1, - description: queueItemDescription_1 -}; -let queueItemDescription_2 = { - mediaId: '002', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon: imagePixel, - iconUri: 'http://www.icon.uri.com', - extras: {'extras':'any'} -}; -let queueItem_2 = { - itemId: 2, - description: queueItemDescription_2 -}; -let queueItemsArray = [queueItem_1, queueItem_2]; -session.setAVQueueItems(queueItemsArray, function (err) { - if (err) { - console.info(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetAVQueueItems successfully`); - } -}); +currentAVSession.off('skipToQueueItem'); ``` -### setAVQueueTitle10+ +### off('handleKeyEvent')10+ -setAVQueueTitle(title: string): Promise\ +off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void -Sets a name for the playlist. This API uses a promise to return the result. +Unsubscribes from key events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------ | ------ | ---- | -------------- | -| title | string | Yes | Name of the playlist.| - -**Return value** - -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type, which is **'handleKeyEvent'** in this case. | +| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | No | Callback used for unsubscription. The **event** parameter in the callback indicates the key event.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -1260,28 +3729,23 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let queueTitle = 'QUEUE_TITLE'; -session.setAVQueueTitle(queueTitle).then(() => { - console.info(`SetAVQueueTitle successfully`); -}).catch((err) => { - console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); -}); +currentAVSession.off('handleKeyEvent'); ``` -### setAVQueueTitle10+ +### off('outputDeviceChange')10+ -setAVQueueTitle(title: string, callback: AsyncCallback\): void +off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void -Sets a name for the playlist. This API uses an asynchronous callback to return the result. +Unsubscribes from playback device change events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------- | ---- | ----------------------------------------------------------- | -| title | string | Yes | Name of the playlist. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | +| type | string | Yes | Event type, which is **'outputDeviceChange'** in this case. | +| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -1295,101 +3759,53 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let queueTitle = 'QUEUE_TITLE'; -session.setAVQueueTitle(queueTitle, function (err) { - if (err) { - console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetAVQueueTitle successfully`); - } -}); +currentAVSession.off('outputDeviceChange'); ``` -### setLaunchAbility10+ -setLaunchAbility(ability: WantAgent): Promise\ +### off('commonCommand')10+ -Sets a launcher ability. This API uses a promise to return the result. +off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void + +Unsubscribes from custom control command change events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Application attributes, such as the bundle name, ability name, and deviceID.| - -**Return value** - -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'commonCommand'** in this case. | +| callback | (command: string, args: {[key:string]: Object}) => void | No | Callback used for unsubscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | | 6600102 | The session does not exist. | **Example** ```js -import wantAgent from '@ohos.app.ability.wantAgent'; - -// WantAgentInfo object -let wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.example.myapplication", - abilityName: "EntryAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: wantAgent.OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -wantAgent.getWantAgent(wantAgentInfo).then((agent) => { - session.setLaunchAbility(agent).then(() => { - console.info(`SetLaunchAbility successfully`); - }).catch((err) => { - console.info(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); - }); -}); +currentAVSession.off('commonCommand'); ``` -### setLaunchAbility10+ +### stopCasting10+ -setLaunchAbility(ability: WantAgent, callback: AsyncCallback\): void +stopCasting(callback: AsyncCallback\): void -Sets a launcher ability. This API uses an asynchronous callback to return the result. +Stops castings. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | -| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Application attributes, such as the bundle name, ability name, and deviceID. | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -1397,77 +3813,33 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600109 | The remote connection is not established. | **Example** ```js -import wantAgent from '@ohos.app.ability.wantAgent'; - -// WantAgentInfo object -let wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.example.myapplication", - abilityName: "EntryAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: wantAgent.OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -wantAgent.getWantAgent(wantAgentInfo).then((agent) => { - session.setLaunchAbility(agent, function (err) { - if (err) { - console.info(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetLaunchAbility successfully`); - } - }); +currentAVSession.stopCasting(function (err) { + if (err) { + console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`stopCasting successfully`); + } }); ``` -### dispatchSessionEvent10+ - -dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\ - -Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses a promise to return the result. It is called by the provider. - -**System capability**: SystemCapability.Multimedia.AVSession.Core +### stopCasting10+ -**Parameters** +stopCasting(): Promise\ -| Name | Type | Mandatory| Description | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| event | string | Yes | Name of the session event.| -| args | {[key: string]: any} | Yes | Event content in key-value pair format.| +Stops castings. This API uses a promise to return the result. -> **NOTE** -> -> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md). +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Return value** | Type | Description | | -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +| Promise\ | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -1475,87 +3847,69 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600109 | The remote connection is not established. | **Example** ```js -let eventName = "dynamic_lyric"; -let args = { - lyric : "This is lyric" -} -await session.dispatchSessionEvent(eventName, args).catch((err) => { - console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); -}) +currentAVSession.stopCasting().then(() => { + console.info(`stopCasting successfully`); +}).catch((err) => { + console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### dispatchSessionEvent10+ - -dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\): void - -Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses an asynchronous callback to return the result. It is called by the provider. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -**Parameters** +## AVCastControlCommandType10+ -| Name | Type | Mandatory| Description | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| event | string | Yes | Name of the session event.| -| args | {[key: string]: any} | Yes | Event content in key-value pair format.| -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +Enumerates the commands that can be sent by a cast controller. -> **NOTE** -> -> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md). +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Error codes** +| Name | Type | Description | +| -------------- | ------ | ------------ | +| play | string | Play the media. | +| pause | string | Pause the playback. | +| stop | string | Stop the playback. | +| playNext | string | Play the next media asset. | +| playPrevious | string | Play the previous media asset. | +| fastForward | string | Fast-forward. | +| rewind | string | Rewind. | +| seek | numbder | Seek to a playback position.| +| setSpeed | number | Set the playback speed.| +| setLoopMode | string | Set the loop mode.| +| toggleFavorite | string | Favorite the media asset. | +| setVolume | number | Set the volume. | -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +## AVCastControlCommand10+ -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +Defines the command that can be sent by a cast controller. -**Example** +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -```js -let eventName = "dynamic_lyric"; -let args = { - lyric : "This is lyric" -} -await session.dispatchSessionEvent(eventName, args, (err) => { - if(err) { - console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); - } -}) -``` +| Name | Type | Mandatory| Description | +| --------- | ------------------------------------------------- | ---- | -------------- | +| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | Yes | Command. | +| parameter | [LoopMode](#loopmode10) | string | number | No | Parameters carried in the command.| -### setExtras10+ +## AVCastController10+ -setExtras(extras: {[key: string]: Object}): Promise\ +After a casting connection is set up, you can call [avSession.getAVCastController](#getavcastcontroller10) to obtain the cast controller. Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information. -Sets a custom media packet in the form of key-value pairs. This API uses a promise to return the result. It is called by the provider. +### setDisplaySurface10+ -**System capability**: SystemCapability.Multimedia.AVSession.Core +setDisplaySurface(surfaceId: string): Promise\ -**Parameters** +Sets the surface ID for playback, which is used at the cast receiver (sink). This API uses a promise to return the result. -| Name | Type | Mandatory| Description | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| extras | {[key: string]: Object} | Yes | Key-value pairs of the custom media packet.| +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -> **NOTE** -> -> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md). +**System API**: This is a system API. **Return value** -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| +| Type | Description | +| --------------------------------------------- | --------------------------- | +| Promise\ | Promise used to return the result.| **Error codes** @@ -1563,38 +3917,30 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600109 | The remote connection is not established. | **Example** - ```js -let extras = { - extras : "This is custom media packet" -} -await session.setExtras(extras).catch((err) => { - console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); -}) +aVCastController.setDisplaySurface().then(() => { + console.info(`setDisplaySurface : SUCCESS :`); +}); ``` -### setExtras10+ +### setDisplaySurface10+ -setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\): void +setDisplaySurface(surfaceId: string, callback: AsyncCallback\): void -Sets a custom media packet in the form of key-value pairs. This API uses an asynchronous callback to return the result. It is called by the provider. +Sets the surface ID for playback, which is used at the cast receiver (sink). This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Parameters** +**System API**: This is a system API. -| Name | Type | Mandatory| Description | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| extras | {[key: string]: any} | Yes | Key-value pairs of the custom media packet.| -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +**Parameters** -> **NOTE** -> -> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md). +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| **Error codes** @@ -1602,35 +3948,32 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600109 | The remote connection is not established. | **Example** - ```js -let extras = { - extras : "This is custom media packet" -} -await session.setExtras(extras, (err) => { - if(err) { - console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); +aVCastController.setDisplaySurface(function (err, value) { + if (err) { + console.info(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`setDisplaySurface : SUCCESS : state : ${value}`); } -}) +}); ``` -### getController10+ +### getAVPlaybackState10+ -getController(): Promise\ +getAVPlaybackState(callback: AsyncCallback\): void -Obtains the controller corresponding to this session. This API uses a promise to return the result. +Obtains the remote playback state. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Return value** +**Parameters** -| Type | Description | -| ---------------------------------------------------- | ----------------------------- | -| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.| +| Name | Type | Mandatory| Description | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the remote playback state.| **Error codes** @@ -1638,34 +3981,33 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600101 | Session service exception | **Example** ```js -let controller; -session.getController().then((avcontroller) => { - controller = avcontroller; - console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`); -}).catch((err) => { - console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); +aVCastController.getAVPlaybackState(function (err, state) { + if (err) { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getAVPlaybackState : SUCCESS`); + } }); ``` -### getController10+ +### getAVPlaybackState10+ -getController(callback: AsyncCallback\): void +getAVPlaybackState(): Promise\; -Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result. +Obtains the remote playback state. This API uses a promise to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | -------------------------- | -| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes | Callback used to return the session controller.| +| Type | Description | +| --------- | ------------------------------------------------------------ | +| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state.| **Error codes** @@ -1673,36 +4015,38 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600101 | Session service exception | **Example** ```js -let controller; -session.getController(function (err, avcontroller) { - if (err) { - console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - controller = avcontroller; - console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`); - } +aVCastController.getAVPlaybackState().then((state) => { + console.info(`getAVPlaybackState : SUCCESS :`); +}).catch((err) => { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getOutputDevice10+ +### sendControlCommand10+ -getOutputDevice(): Promise\ +sendControlCommand(command: AVCastControlCommand): Promise\ -Obtains information about the output device for this session. This API uses a promise to return the result. +Sends a control command to the session through the controller. This API uses a promise to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast + +**Parameters** + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes | Command to send.| **Return value** -| Type | Description | -| ---------------------------------------------- | --------------------------------- | -| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.| +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -1711,66 +4055,87 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600105 | Invalid session command. | +| 6600109 | The remote connection is not established. | **Example** ```js -session.getOutputDevice().then((outputDeviceInfo) => { - console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); +let avCommand = {command:'play'}; +// let avCommand = {command:'pause'}; +// let avCommand = {command:'stop'}; +// let avCommand = {command:'playNext'}; +// let avCommand = {command:'playPrevious'}; +// let avCommand = {command:'fastForward'}; +// let avCommand = {command:'rewind'}; +// let avCommand = {command:'seek', parameter:10}; +aVCastController.sendControlCommand(avCommand).then(() => { + console.info(`SendControlCommand successfully`); }).catch((err) => { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getOutputDevice10+ +### sendControlCommand10+ -getOutputDevice(callback: AsyncCallback\): void +sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\): void -Obtains information about the output device for this session. This API uses an asynchronous callback to return the result. +Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | ---- | ------------------------------ | -| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------ | +| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes | Command to send.| +| callback | AsyncCallback\ | 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 [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| 6600105 | Invalid session command. | +| 6600109 | The remote connection is not established. | **Example** ```js -session.getOutputDevice(function (err, outputDeviceInfo) { +let avCommand = {command:'play'}; +// let avCommand = {command:'pause'}; +// let avCommand = {command:'stop'}; +// let avCommand = {command:'playNext'}; +// let avCommand = {command:'playPrevious'}; +// let avCommand = {command:'fastForward'}; +// let avCommand = {command:'rewind'}; +// let avCommand = {command:'seek', parameter:10}; +aVCastController.sendControlCommand(avCommand, function (err) { if (err) { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); + console.info(`SendControlCommand successfully`); } }); ``` -### activate10+ +### prepare10+ -activate(): Promise\ +prepare(item: AVQueueItem, callback: AsyncCallback\): void -Activates this session. A session can be used only after being activated. This API uses a promise to return the result. +Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Return value** +**Parameters** -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. **Error codes** @@ -1779,31 +4144,56 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.activate().then(() => { - console.info(`Activate : SUCCESS `); -}).catch((err) => { - console.info(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); +// Set playback parameters. +var playItem = { + itemId: 0, + description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' + } +}; +// Prepare for playback. This operation triggers loading and buffering, but not the actual playback. +aVCastController.prepare(playItem, () => { + console.info('prepare done'); }); ``` -### activate10+ -activate(callback: AsyncCallback\): void +### prepare10+ -Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result. +prepare(item: AVQueueItem): Promise\ -**System capability**: SystemCapability.Multimedia.AVSession.Core +Prepares for the playback of a media asset. This API uses a promise to return the result. + + +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -1812,33 +4202,50 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | + **Example** ```js -session.activate(function (err) { - if (err) { - console.info(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`Activate : SUCCESS `); +// Set playback parameters. +var playItem = { + itemId: 0, + description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' } +}; +// Prepare for playback. This operation triggers loading and buffering, but not the actual playback. +aVCastController.prepare(playItem, () => { + console.info('prepare done'); }); ``` -### deactivate10+ +### start10+ -deactivate(): Promise\ +start(item: AVQueueItem, callback: AsyncCallback\): void -Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result. +Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Return value** +**Parameters** -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. **Error codes** @@ -1847,33 +4254,56 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.deactivate().then(() => { - console.info(`Deactivate : SUCCESS `); -}).catch((err) => { - console.info(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); +// Set playback parameters. +var playItem = { +itemId: 0, +description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' +} +}; + +// Start playback. +aVCastController.start(playItem, () => { + console.info('play done'); }); ``` -### deactivate10+ +### start10+ -deactivate(callback: AsyncCallback\): void +start(item: AVQueueItem): Promise\ -Deactivates this session. This API uses an asynchronous callback to return the result. +Prepares for the playback of a media asset. This API uses a promise to return the result. -Deactivates this session. You can use [activate](#activate10) to activate the session again. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| + +**Return value** + +| Type | Description | +| -------------- | ----------------------------- | +| Promise\ | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -1882,33 +4312,51 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | + **Example** ```js -session.deactivate(function (err) { - if (err) { - console.info(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`Deactivate : SUCCESS `); - } +// Set playback parameters. +var playItem = { +itemId: 0, +description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' +} +}; +// Start playback. +aVCastController.start(playItem).then(() => { + console.info(`start successfully`); +}).catch((err) => { + console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### destroy10+ +### getCurrentItem10+ -destroy(): Promise\ +getCurrentItem(callback: AsyncCallback\): void -Destroys this session. This API uses a promise to return the result. +Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Return value** +**Parameters** -| Type | Description | -| -------------- | ----------------------------- | -| Promise\ | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -1917,31 +4365,32 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.destroy().then(() => { - console.info(`Destroy : SUCCESS `); -}).catch((err) => { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); +aVCastController.getCurrentItem(function (err, value) { + if (err) { + console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getCurrentItem successfully`); + } }); ``` -### destroy10+ +### getCurrentItem10+ -destroy(callback: AsyncCallback\): void +getCurrentItem(): Promise\ -Destroys this session. This API uses an asynchronous callback to return the result. +Obtains the information about the media asset that is being played. This API uses a promise to return the result. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.| +| Type | Description | +| -------------- | ----------------------------- | +| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.| **Error codes** @@ -1950,308 +4399,274 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.destroy(function (err) { - if (err) { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`Destroy : SUCCESS `); - } +aVCastController.getCurrentItem().then((AVQueueItem) => { + console.info(`getCurrentItem successfully`); +}).catch((err) => { + console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### on('play'|'pause'|'stop'|'playNext'|'playPrevious'|'fastForward'|'rewind')10+ +### on('playbackStateChange')10+ -on(type: 'play'|'pause'|'stop'|'playNext'|'playPrevious'|'fastForward'|'rewind', callback: () => void): void +on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void): void -Subscribes to playback command events. +Subscribes to playback state change events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The following events are supported: **'play'**, **'pause'**, **'stop'**, **'playNext'**, **'playPrevious'**, **'fastForward'**, and **'rewind'**.
The event is reported when the corresponding playback command is sent to the session.| -| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.| +| filter | Array\ | 'all' | Yes | The value **'all'** indicates that any playback state field change will trigger the event, and **Array** indicates that only changes to the listed playback state field will trigger the event.| +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('play', () => { - console.info(`on play entry`); -}); -session.on('pause', () => { - console.info(`on pause entry`); -}); -session.on('stop', () => { - console.info(`on stop entry`); -}); -session.on('playNext', () => { - console.info(`on playNext entry`); -}); -session.on('playPrevious', () => { - console.info(`on playPrevious entry`); -}); -session.on('fastForward', () => { - console.info(`on fastForward entry`); +aVCastController.on('playbackStateChange', 'all', (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); }); -session.on('rewind', () => { - console.info(`on rewind entry`); + +let playbackFilter = ['state', 'speed', 'loopMode']; +aVCastController.on('playbackStateChange', playbackFilter, (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); }); ``` -### on('seek')10+ +### off('playbackStateChange')10+ -on(type: 'seek', callback: (time: number) => void): void +off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void -Subscribes to the seek event. +Unsubscribes from playback state change events. This API is called by the controller. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'seek'** is reported when the seek command is sent to the session.| -| callback | (time: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'playbackStateChange'** in this case. | +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | No | Callback used for unsubscription. The **state** parameter in the callback indicates the changed playback state.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** -The session does not exist + ```js -session.on('seek', (time) => { - console.info(`on seek entry time : ${time}`); -}); +aVCastController.off('playbackStateChange'); ``` -### on('setSpeed')10+ +### on('mediaItemChange')10+ -on(type: 'setSpeed', callback: (speed: number) => void): void +on(type: 'mediaItemChange', callback: Callback\): void -Subscribes to the event for setting the playback speed. +Subscribes to media asset change events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'setSpeed'** is reported when the command for setting the playback speed is sent to the session.| -| callback | (speed: number) => void | Yes | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.| +| callback | (state: [AVQueueItem](#avqueueitem10)) => void | Yes | Callback used for subscription. **AVQueueItem** is the media asset that is being played. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('setSpeed', (speed) => { - console.info(`on setSpeed speed : ${speed}`); +aVCastController.on('mediaItemChange', (item) => { + console.info(`on mediaItemChange state : ${item.itemId}`); }); ``` -### on('setLoopMode')10+ +### off('mediaItemChange')10+ -on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void +off(type: 'mediaItemChange'): void -Subscribes to the event for setting the loop mode. +Unsubscribes from media asset change events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------- | ---- | ---- | -| type | string | Yes | Event type. The event **'setLoopMode'** is reported when the command for setting the loop mode is sent to the session.| -| callback | (mode: [LoopMode](#loopmode10)) => void | Yes | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'mediaItemChange'** in this case. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('setLoopMode', (mode) => { - console.info(`on setLoopMode mode : ${mode}`); -}); +aVCastController.off('mediaItemChange'); ``` -### on('toggleFavorite')10+ +### on('playNext')10+ -on(type: 'toggleFavorite', callback: (assetId: string) => void): void +on(type: 'playNext', callback: Callback\): void -Subscribes to the event for favoriting a media asset. +Subscribes to playNext command events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'toggleFavorite'** is reported when the command for favoriting the media asset is sent to the session.| -| callback | (assetId: string) => void | Yes | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.| +| callback | Callback\ | Yes | Callback used to return the result. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('toggleFavorite', (assetId) => { - console.info(`on toggleFavorite mode : ${assetId}`); +aVCastController.on('playNext', () => { + console.info(`on playNext`); }); ``` -### on('skipToQueueItem')10+ +### off('playNext')10+ -on(type: 'skipToQueueItem', callback: (itemId: number) => void): void +off(type: 'playNext'): void -Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item. +Unsubscribes from playNext command events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The event **'skipToQueueItem'** is reported when the command for selecting an item in the playlist is sent to the session.| -| callback | (itemId: number) => void | Yes | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'playNext'** in this case. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('skipToQueueItem', (itemId) => { - console.info(`on skipToQueueItem id : ${itemId}`); -}); +aVCastController.off('playNext'); ``` -### on('handleKeyEvent')10+ +### on('playPrevious')10+ -on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void +on(type: 'playPrevious', callback: Callback\): void -Subscribes to the key event. +Subscribes to playPrevious command events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'handleKeyEvent'** is reported when a key event is sent to the session.| -| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | Yes | Callback used for subscription. The **event** parameter in the callback indicates the key event. | +| type | string | Yes | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.| +| callback | Callback\ | Yes | Callback used to return the result. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('handleKeyEvent', (event) => { - console.info(`on handleKeyEvent event : ${event}`); +aVCastController.on('playPrevious', () => { + console.info(`on playPrevious`); }); ``` -### on('outputDeviceChange')10+ +### off('playPrevious')10+ -on(type: 'outputDeviceChange', callback: (device: OutputDeviceInfo) => void): void +off(type: 'playPrevious'): void -Subscribes to output device changes. +Unsubscribes from the playPrevious command event. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'outputDeviceChange'** is reported when the output device changes.| -| callback | (device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback used for subscription. The **device** parameter in the callback indicates the output device information. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'playPrevious'** in this case. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('outputDeviceChange', (device) => { - console.info(`on outputDeviceChange device isRemote : ${device.isRemote}`); -}); +aVCastController.off('playPrevious'); ``` -### on('commonCommand')10+ +### on('seekDone')10+ -on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void +on(type: 'seekDone', callback: Callback\): void -Subscribes to custom control command changes. +Subscribes to seek done events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'commonCommand'** is reported when a custom control command changes.| -| callback | (commonCommand: string, args: {[key:string]: Object}) => void | Yes | Callback used for subscription. The **commonCommand** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command. The parameters must be the same as those set in **sendCommand**. | +| type | string | Yes | Event type. The event **'seekDone'** is triggered when the seek operation is complete.| +| callback | Callback\ | Yes | Callback used to return the position after the seek operation. | **Error codes** @@ -2260,298 +4675,366 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.on('commonCommand', (commonCommand, args) => { - console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); +aVCastController.on('seekDone', (pos) => { + console.info(`on seekDone pos: ${pos} `); }); ``` -### off('play'|'pause'|'stop'|'playNext'|'playPrevious'|'fastForward'|'rewind')10+ +### off('seekDone')10+ -off(type: 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind', callback?: () => void): void +off(type: 'seekDone'): void -Unsubscribes from playback command events. +Unsubscribes from the seek done events. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The following events are supported: **'play'**, **'pause'**, **'stop'**, **'playNext'**, **'playPrevious'**, **'fastForward'**, and **'rewind'**.| -| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'seekDone'** in this case. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | **Example** ```js -session.off('play'); -session.off('pause'); -session.off('stop'); -session.off('playNext'); -session.off('playPrevious'); -session.off('fastForward'); -session.off('rewind'); +aVCastController.off('seekDone'); ``` -### off('seek')10+ - -off(type: 'seek', callback?: (time: number) => void): void - -Unsubscribes from the seek event. +### on('videoSizeChange')10+ -**System capability**: SystemCapability.Multimedia.AVSession.Core +on(type: 'videoSizeChange', callback: (width:number, height:number) => void): void -**Parameters** +Subscribes to video size change events. -| Name | Type | Mandatory| Description | -| -------- | ---------------------- | ---- | ----------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'seek'**. | -| callback | (time: number) => void | No | Callback used for unsubscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Error codes** +**System API**: This is a system API. -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +**Parameters** -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| Parameter | Type | Mandatory | Description | +| type | string | Yes | Event type. The event **'videoSizeChange'** is triggered when the video size changes. | +| callback | (width:number, height:number) => void | Yes | Callback used to return the video width and height. | **Example** ```js -session.off('seek'); +aVCastController.on('videoSizeChange', (width, height) => { + console.info(`width : ${width} `); + console.info(`height: ${height} `); +}); ``` -### off('setSpeed')10+ - -off(type: 'setSpeed', callback?: (speed: number) => void): void - -Unsubscribes from the event for setting the playback speed. +### off('videoSizeChange')10+ -**System capability**: SystemCapability.Multimedia.AVSession.Core +off(type: 'videoSizeChange'): void -**Parameters** +Unsubscribes from video size changes. -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | -------------------------------------------| -| type | string | Yes | Event type. The value is fixed at **'setSpeed'**. | -| callback | (speed: number) => void | No | Callback used for unsubscription. The **speed** parameter in the callback indicates the playback speed.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -**Error codes** +**System API**: This is a system API. -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +**Parameters** -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| Name | Type | Mandatory | Description | +| type | string | Yes | Event type, which is **'videoSizeChange'** in this case. | **Example** ```js -session.off('setSpeed'); +aVCastController.off('videoSizeChange'); ``` -### off('setLoopMode')10+ +### on('error')10+ -off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void +on(type: 'error', callback: ErrorCallback): void -Unsubscribes from the event for setting loop mode. +Subscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------- | ---- | ----- | -| type | string | Yes | Event type. The value is fixed at **'setLoopMode'**.| -| callback | (mode: [LoopMode](#loopmode10)) => void | No | Callback used for unsubscription. The **mode** parameter in the callback indicates the loop mode.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.| +| callback | function | Yes | Callback used to return the error code ID and error message.| **Error codes** -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +For details about the error codes, see [Media Error Codes](../errorcodes/errorcode-media.md). -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| ID| Error Message | +| -------- | --------------------- | +| 5400101 | No memory. | +| 5400102 | Operation not allowed. | +| 5400103 | I/O error. | +| 5400104 | Time out. | +| 5400105 | Service died. | +| 5400106 | Unsupport format. | **Example** ```js -session.off('setLoopMode'); +aVCastController.on('error', (error) => { + console.error('error happened,and error message is :' + error.message) + console.error('error happened,and error code is :' + error.code) +}) ``` -### off('toggleFavorite')10+ +### off('error')10+ -off(type: 'toggleFavorite', callback?: (assetId: string) => void): void +off(type: 'error'): void -Unsubscribes from the event for favoriting a media asset. +Unsubscribes from remote AVPlayer errors. -**System capability**: SystemCapability.Multimedia.AVSession.Core +**System capability**: SystemCapability.Multimedia.AVSession.AVCast **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------- | ---- | -------------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'toggleFavorite'**. | -| callback | (assetId: string) => void | No | Callback used for unsubscription. The **assetId** parameter in the callback indicates the media asset ID.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ----------------------------------------- | +| type | string | Yes | Event type, which is **'error'** in this case.| **Error codes** -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +For details about the error codes, see [Media Error Codes](../errorcodes/errorcode-media.md). -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| ID| Error Message | +| -------- | --------------------- | +| 5400101 | No memory. | +| 5400102 | Operation not allowed. | +| 5400103 | I/O error. | +| 5400104 | Time out. | +| 5400105 | Service died. | +| 5400106 | Unsupport format. | **Example** ```js -session.off('toggleFavorite'); +aVCastController.off('error') ``` -### off('skipToQueueItem')10+ +## ConnectionState10+ -off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void +Enumerates the connection states. -Unsubscribes from the event that indicates an item in the playlist is selected. +**System capability**: SystemCapability.Multimedia.AVSession.Core + +| Name | Value | Description | +| --------------------------- | ---- | ----------- | +| STATE_CONNECTING | 0 | The device is connecting. | +| STATE_CONNECTED | 1 | The device is connected.| +| STATE_DISCONNECTED | 6 | The device is disconnected.| + +## AVMetadata10+ + +Describes the media metadata. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Parameters** +| Name | Type | Mandatory| Description | +| --------------- |-------------------------| ---- |---------------------------------------------------------------------| +| assetId | string | Yes | Media ID. | +| title | string | No | Title. | +| artist | string | No | Artist. | +| author | string | No | Author. | +| album | string | No | Album name. | +| writer | string | No | Writer. | +| composer | string | No | composer. | +| duration | number | No | Media duration, in ms. | +| mediaImage | image.PixelMap | string | No | Pixel map or image path (local path or network path) of the image. | +| publishDate | Date | No | Release date. | +| subtitle | string | No | Subtitle. | +| description | string | No | Media description. | +| lyric | string | No | Lyric file path (local path or network path).| +| previousAssetId | string | No | ID of the previous media asset. | +| nextAssetId | string | No | ID of the next media asset. | -| Name | Type | Mandatory| Description | -| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'skipToQueueItem'**. | -| callback | (itemId: number) => void | No | Callback used for unsubscription. The **itemId** parameter in the callback indicates the ID of the item.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| +## AVMediaDescription10+ -**Error codes** +Describes the attributes related to the media metadata in the playlist. -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +**System capability**: SystemCapability.Multimedia.AVSession.Core -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| Name | Type | Mandatory | Description | +| ------------ | ----------------------- | ---- | ----------------------- | +| mediaId | string | Yes | Media ID in the playlist. | +| title | string | No | Name of the media asset in the playlist. | +| subtitle | string | No | Subname of the media asset in the playlist. | +| description | string | No | Description of the media asset in the playlist. | +| icon | image.PixelMap | No | Pixel map of the image of the media asset in the playlist.| +| iconUri | string | No | Path of the image of the media asset in the playlist.| +| extras | {[key: string]: any} | No | Additional fields of the media asset in the playlist. | +| mediaUri | string | No | URI of the media asset in the playlist. | +| mediaType | string | No | Type of the media asset in the playlist. | +| mediaSize | number | No | Size of the media asset in the playlist. | +| albumTitle | string | No | Album name of the media asset in the playlist. | +| albumCoverUri | string | No | URI of the album title of the media asset in the playlist. | +| lyricContent | string | No | Lyric content of the media asset in the playlist. | +| lyricUri | string | No | Lyric URI of the media asset in the playlist. | +| artist | string | No | Author of the lyric of the media asset in the playlist. | +| fdSrc | media.AVFileDescriptor | No | Handle to the local media file in the playlist. | +| duration | number | No | Playback duration of the media asset in the playlist. | +| startPosition | number | No | Start position for playing the media asset in the playlist. | +| creditsPosition | number | No | Position for playing the closing credits of the media asset in the playlist. | +| appName | string | No | Name of the application provided by the playlist. | -**Example** +## AVQueueItem10+ -```js -session.off('skipToQueueItem'); -``` +Describes the attributes of an item in the playlist. -### off('handleKeyEvent')10+ +**System capability**: SystemCapability.Multimedia.AVSession.Core -off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void +| Name | Type | Mandatory| Description | +| ------------ | ------------------------------------------ | ---- | --------------------------- | +| itemId | number | Yes | ID of an item in the playlist. | +| description | [AVMediaDescription](#avmediadescription10) | Yes | Media metadata of the item in the playlist. | -Unsubscribes from the key event. +## AVPlaybackState10+ + +Describes the information related to the media playback state. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Parameters** +| Name | Type | Mandatory| Description | +| ------------ | ------------------------------------- | ---- | ------- | +| state | [PlaybackState](#playbackstate) | No | Playback state.| +| speed | number | No | Playback speed.| +| position | [PlaybackPosition](#playbackposition) | No | Playback position.| +| bufferedTime | number | No | Buffered time.| +| loopMode | [LoopMode](#loopmode10) | No | Loop mode.| +| isFavorite | boolean | No | Whether the media asset is favorited.| +| activeItemId10+ | number | No | ID of the item that is being played.| +| volume10+ | number | No | Media volume.| +| extras10+ | {[key: string]: Object} | No | Custom media data.| + +## PlaybackPosition10+ -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'handleKeyEvent'**. | -| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | No | Callback used for unsubscription. The **event** parameter in the callback indicates the key event.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +Describes the information related to the playback position. -**Error codes** +**System capability**: SystemCapability.Multimedia.AVSession.Core -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +| Name | Type | Mandatory| Description | +| ----------- | ------ | ---- | ------------------ | +| elapsedTime | number | Yes | Elapsed time, in ms.| +| updateTime | number | Yes | Updated time, in ms.| -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +## AVCastCategory10+ -**Example** +Enumerates the cast categories. -```js -session.off('handleKeyEvent'); -``` +**System capability**: SystemCapability.Multimedia.AVSession.AVCast -### off('outputDeviceChange')10+ +| Name | Value | Description | +| --------------------------- | ---- | ----------- | +| CATEGORY_LOCAL | 0 | Local playback. The sound is played from the local device or a connected Bluetooth headset by default. | +| CATEGORY_REMOTE | 1 | Remote playback. The sound or images are played from a remote device. | -off(type: 'outputDeviceChange', callback?: (device: OutputDeviceInfo) => void): void +## DeviceType10+ -Unsubscribes from playback device changes. +Enumerates the output device types. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Parameters** +| Name | Value | Description | +| --------------------------- | ---- | ----------- | +| DEVICE_TYPE_LOCAL | 0 | Local device. | +| DEVICE_TYPE_BLUETOOTH | 10 | Bluetooth device. | +| DEVICE_TYPE_TV | 2 | TV.
**System capability**: SystemCapability.Multimedia.AVSession.AVCast| +| DEVICE_TYPE_SMART_SPEAKER | 3 | Speaker.
**System capability**: SystemCapability.Multimedia.AVSession.AVCast| -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | -| type | string | Yes | Event type. The value is fixed at **'outputDeviceChange'**. | -| callback | (device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.
If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +## DeviceInfo10+ -**Error codes** +Describes the information related to the output device. -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +**System capability**: SystemCapability.Multimedia.AVSession.Core -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| Name | Type | Mandatory| Description | +| ---------- | -------------- | ---- | ---------------------- | +| castCategory | AVCastCategory | Yes | Cast category. | +| deviceId | string | Yes | ID of the output device. | +| deviceName | string | Yes | Name of the output device. | +| deviceType | DeviceType | Yes | Type of the output device. | +| ipAddress | string | No | IP address of the output device.
This is a system API.
**System capability**: SystemCapability.Multimedia.AVSession.AVCast | +| providerId | number | No | Vendor of the output device.
This is a system API.
**System capability**: SystemCapability.Multimedia.AVSession.AVCast | -**Example** +## OutputDeviceInfo10+ -```js -session.off('outputDeviceChange'); -``` +Describes the information related to the output device. +**System capability**: SystemCapability.Multimedia.AVSession.Core -### off('commonCommand')10+ +| Name | Type | Mandatory| Description | +| ---------- | -------------- | ---- | ---------------------- | +| devices | Array\ | Yes | Output devices. | -off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void +## LoopMode10+ -Unsubscribes from custom control command changes. +Enumerates the loop modes of media playback. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Parameters** +| Name | Value | Description | +| ------------------ | ---- | -------- | +| LOOP_MODE_SEQUENCE | 0 | Sequential playback.| +| LOOP_MODE_SINGLE | 1 | Single loop.| +| LOOP_MODE_LIST | 2 | Playlist loop.| +| LOOP_MODE_SHUFFLE | 3 | Shuffle.| -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'commonCommand'**. | -| callback | (command: string, args: {[key:string]: Object}) => void | No | Callback used for unsubscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +## PlaybackState10+ -**Error codes** +Enumerates the media playback states. -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). +**System capability**: SystemCapability.Multimedia.AVSession.Core -| ID| Error Message| -| -------- | ---------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | +| Name | Value | Description | +| --------------------------- | ---- | ----------- | +| PLAYBACK_STATE_INITIAL | 0 | Initial. | +| PLAYBACK_STATE_PREPARE | 1 | Preparing. | +| PLAYBACK_STATE_PLAY | 2 | Playing. | +| PLAYBACK_STATE_PAUSE | 3 | Paused. | +| PLAYBACK_STATE_FAST_FORWARD | 4 | Fast-forwarding. | +| PLAYBACK_STATE_REWIND | 5 | Rewinding. | +| PLAYBACK_STATE_STOP | 6 | Stop the playback. | +| PLAYBACK_STATE_COMPLETED | 7 | Playback complete. | +| PLAYBACK_STATE_RELEASED | 8 | Released. | +| PLAYBACK_STATE_ERROR | 9 | Error. | -**Example** +## AVSessionDescriptor -```js -session.off('commonCommand'); -``` +Declares the session descriptor. +**System capability**: SystemCapability.Multimedia.AVSession.Manager + +**System API**: This is a system API. +| Name | Type | Readable| Writable| Description | +| --------------| ---------------- |-----|-----|------| +| sessionId | string | Yes | No| Session ID. | +| type | [AVSessionType](#avsessiontype10) | Yes | No | Session type. | +| sessionTag | string | Yes | No | Custom session name. | +| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | No | Information about the application to which the session belongs, including the bundle name and ability name.| +| isActive | boolean | Yes | No | Whether the session is activated. | +| isTopSession | boolean | Yes | No | Whether the session is the top session. | +| outputDevice | [OutputDeviceInfo](#outputdeviceinfo10) | Yes | No | Information about the output device. | ## AVSessionController10+ -An AV session controller is created by calling [avSession.createController](#avsessioncreatecontroller). Through the AV session controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information. +An AV session controller is created by calling [avSession.createController](#avsessioncreatecontroller). Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information. ### Attributes @@ -2564,27 +5047,27 @@ An AV session controller is created by calling [avSession.createController](#avs **Example** ```js -let sessionId; -await avSession.createController(session.sessionId).then((controller) => { - sessionId = controller.sessionId; +let AVSessionController; +avSession.createController(currentAVSession.sessionId).then((controller) => { + AVSessionController = controller; }).catch((err) => { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` ### getAVPlaybackState10+ -getAVPlaybackState(): Promise\ +getAVPlaybackState(callback: AsyncCallback\): void -Obtains the information related to the playback state. This API uses a promise to return the result. +Obtains the remote playback state. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Return value** +**Parameters** -| Type | Description | -| --------------------------------------------- | --------------------------- | -| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the **AVPlaybackState** object.| +| Name | Type | Mandatory| Description | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the remote playback state.| **Error codes** @@ -2597,27 +5080,30 @@ For details about the error codes, see [AVSession Management Error Codes](../err | 6600103 | The session controller does not exist. | **Example** + ```js -controller.getAVPlaybackState().then((playbackState) => { - console.info(`GetAVPlaybackState : SUCCESS : state : ${playbackState.state}`); -}).catch((err) => { - console.info(`GetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); +avsessionController.getAVPlaybackState(function (err, state) { + if (err) { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getAVPlaybackState : SUCCESS`); + } }); ``` ### getAVPlaybackState10+ -getAVPlaybackState(callback: AsyncCallback\): void +getAVPlaybackState(): Promise\; -Obtains the information related to the playback state. This API uses an asynchronous callback to return the result. +Obtains the remote playback state. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------- | ---- | ---------------------------- | -| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the **AVPlaybackState** object.| +| Type | Description | +| --------- | ------------------------------------------------------------ | +| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state. | **Error codes** @@ -2630,29 +5116,28 @@ For details about the error codes, see [AVSession Management Error Codes](../err | 6600103 | The session controller does not exist. | **Example** + ```js -controller.getAVPlaybackState(function (err, playbackState) { - if (err) { - console.info(`GetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetAVPlaybackState : SUCCESS : state : ${playbackState.state}`); - } +avsessionController.getAVPlaybackState().then((state) => { + console.info(`getAVPlaybackState : SUCCESS :`); +}).catch((err) => { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVQueueItems10+ +### getAVMetadata10+ -getAVQueueItems(): Promise\> +getAVMetadata(): Promise\ -Obtains the information related to the items in the queue. This API uses a promise to return the result. +Obtains the session metadata. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.AVSession.Core **Return value** -| Type | Description | -| --------------------------------------------- | ----------------------------- | -| Promise\> | Promise used to return the items in the queue.| +| Type | Description | +| ----------------------------------- | ----------------------------- | +| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.| **Error codes** @@ -2666,26 +5151,26 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.getAVQueueItems().then((items) => { - console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); +avsessionController.getAVMetadata().then((metadata) => { + console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); }).catch((err) => { - console.info(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVQueueItems10+ +### getAVMetadata10+ -getAVQueueItems(callback: AsyncCallback\>): void +getAVMetadata(callback: AsyncCallback\): void -Obtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result. +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\> | Yes | Callback used to return the items in the playlist.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes | Callback used to return the metadata obtained.| **Error codes** @@ -2699,11 +5184,11 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.getAVQueueItems(function (err, items) { +avsessionController.getAVMetadata(function (err, metadata) { if (err) { - console.info(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); + console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); } }); ``` @@ -2733,11 +5218,12 @@ For details about the error codes, see [AVSession Management Error Codes](../err | 6600103 | The session controller does not exist. | **Example** + ```js -controller.getAVQueueTitle().then((title) => { +avsessionController.getAVQueueTitle().then((title) => { console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); }).catch((err) => { - console.info(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -2767,34 +5253,28 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.getAVQueueTitle(function (err, title) { +avsessionController.getAVQueueTitle(function (err, title) { if (err) { - console.info(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); } }); ``` -### skipToQueueItem10+ +### getAVQueueItems10+ -skipToQueueItem(itemId: number): Promise\ +getAVQueueItems(): Promise\> -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. +Obtains the information related to the items in the queue. This API uses a promise 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.| - **Return value** -| Type | Description | -| -------------- | --------------------------------------------------------------- | -| Promise\ | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.| +| Type | Description | +| --------------------------------------------- | ----------------------------- | +| Promise\> | Promise used to return the items in the queue.| **Error codes** @@ -2809,28 +5289,26 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let queueItemId = 0; -controller.skipToQueueItem(queueItemId).then(() => { - console.info(`SkipToQueueItem successfully`); +avsessionController.getAVQueueItems().then((items) => { + console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); }).catch((err) => { - console.info(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### skipToQueueItem10+ +### getAVQueueItems10+ -skipToQueueItem(itemId: number, callback: AsyncCallback\): void +getAVQueueItems(callback: AsyncCallback\>): 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. +Obtains the information related to the items in the playlist. 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\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------- | ---- | ------------------------- | +| callback | AsyncCallback\> | Yes | Callback used to return the items in the playlist.| **Error codes** @@ -2845,97 +5323,34 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let queueItemId = 0; -controller.skipToQueueItem(queueItemId, function (err) { +avsessionController.getAVQueueItems(function (err, items) { if (err) { - console.info(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`SkipToQueueItem successfully`); + console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); } }); ``` -### getAVMetadata10+ - -getAVMetadata(): Promise\ - -Obtains the session metadata. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -**Return value** - -| Type | Description | -| ----------------------------------- | ----------------------------- | -| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.| - -**Error codes** - -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). - -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | - -**Example** -```js -controller.getAVMetadata().then((metadata) => { - console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); -}).catch((err) => { - console.info(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); -}); -``` - -### getAVMetadata10+ +### skipToQueueItem10+ -getAVMetadata(callback: AsyncCallback\): void +skipToQueueItem(itemId: number): Promise\ -Obtains the session metadata. This API uses an asynchronous callback to return the result. +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. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------- | ---- | -------------------------- | -| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes | Callback used to return the metadata obtained.| - -**Error codes** - -For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). - -| ID| Error Message| -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | - -**Example** -```js -controller.getAVMetadata(function (err, metadata) { - if (err) { - console.info(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); - } -}); -``` - -### getOutputDevice10+ - -getOutputDevice(): Promise\ - -Obtains the output device information. This API uses a promise to return the result. - -**System capability**: SystemCapability.Multimedia.AVSession.Core +| Name | Type | Mandatory| Description | +| ------ | ------- | ---- | ------------------------------------------- | +| itemId | number | Yes | ID of an item in the playlist.| **Return value** -| Type | Description | -| ----------------------------------------------- | --------------------------------- | -| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.| +| Type | Description | +| -------------- | --------------------------------------------------------------- | +| Promise\ | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.| **Error codes** @@ -2944,30 +5359,34 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **Example** + ```js -controller.getOutputDevice().then((deviceInfo) => { - console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); +let queueItemId = 0; +avsessionController.skipToQueueItem(queueItemId).then(() => { + console.info(`SkipToQueueItem successfully`); }).catch((err) => { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getOutputDevice10+ +### skipToQueueItem10+ -getOutputDevice(callback: AsyncCallback\): void +skipToQueueItem(itemId: number, callback: AsyncCallback\): void -Obtains the output device information. This API uses an asynchronous callback to return the result. +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 | -| -------- | ----------------------------------------------------- | ---- | ------------------------------ | -| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | ----------------------------------------------------------- | +| itemId | number | Yes | ID of an item in the playlist. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| **Error codes** @@ -2976,33 +5395,35 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.getOutputDevice(function (err, deviceInfo) { +let queueItemId = 0; +avsessionController.skipToQueueItem(queueItemId, function (err) { if (err) { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); + console.info(`SkipToQueueItem successfully`); } }); ``` -### getExtras10+ +### getOutputDevice10+ -getExtras(): Promise\<{[key: string]: Object}> +getOutputDevice(): Promise\ -Obtains the custom media packet set by the provider. This API uses a promise to return the result. +Obtains the output device information. This API uses a promise to return the result. **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**.| +| Type | Description | +| ----------------------------------------------- | --------------------------------- | +| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.| **Error codes** @@ -3010,32 +5431,31 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 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. | +| 600101 | Session service exception. | +| 600103 | The session controller does not exist. | **Example** ```js -let extras = await controller.getExtras().catch((err) => { - console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); +avsessionController.getOutputDevice().then((deviceInfo) => { + console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); +}).catch((err) => { + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getExtras10+ +### getOutputDevice10+ -getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void +getOutputDevice(callback: AsyncCallback\): void -Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result. +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<{[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**.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | ------------------------------ | +| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| **Error codes** @@ -3043,35 +5463,17 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 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. | +| 600101 | Session service exception. | +| 600103 | The session controller does not exist. | **Example** + ```js -let metadata = { - assetId: "121278", - title: "lose yourself", - artist: "Eminem", - author: "ST", - album: "Slim shady", - writer: "ST", - composer: "ST", - duration: 2222, - mediaImage: "https://www.example.com/example.jpg", - subtitle: "8 Mile", - description: "Rap", - lyric: "https://www.example.com/example.lrc", - previousAssetId: "121277", - nextAssetId: "121279", -}; -controller.getExtras(function (err, extras) { +avsessionController.getOutputDevice(function (err, deviceInfo) { if (err) { - console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`getExtras : SUCCESS : assetId : ${metadata.assetId}`); + console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); } }); ``` @@ -3096,11 +5498,11 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600106 | The session is not activated. | +| 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** @@ -3114,10 +5516,10 @@ For details about the error codes, see [AVSession Management Error Codes](../err let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let event = {action:2, key:keyItem, keys:[keyItem]}; -controller.sendAVKeyEvent(event).then(() => { +avsessionController.sendAVKeyEvent(event).then(() => { console.info(`SendAVKeyEvent Successfully`); }).catch((err) => { - console.info(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -3142,11 +5544,11 @@ For details about the error codes, see [AVSession Management Error Codes](../err | ID| Error Message| | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600106 | The session is not activated. | +| 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** @@ -3154,9 +5556,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let event = {action:2, key:keyItem, keys:[keyItem]}; -controller.sendAVKeyEvent(event, function (err) { +avsessionController.sendAVKeyEvent(event, function (err) { if (err) { - console.info(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`SendAVKeyEvent Successfully`); } @@ -3190,12 +5592,10 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -import wantAgent from '@ohos.app.ability.wantAgent'; - -controller.getLaunchAbility().then((agent) => { +avsessionController.getLaunchAbility().then((agent) => { console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); }).catch((err) => { - console.info(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -3226,11 +5626,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -import wantAgent from '@ohos.app.ability.wantAgent'; - -controller.getLaunchAbility(function (err, agent) { +avsessionController.getLaunchAbility(function (err, agent) { if (err) { - console.info(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); } @@ -3263,7 +5661,7 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -let time = controller.getRealPlaybackPositionSync(); +let time = avsessionController.getRealPlaybackPositionSync(); ``` ### isActive10+ @@ -3293,10 +5691,10 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.isActive().then((isActive) => { +avsessionController.isActive().then((isActive) => { console.info(`IsActive : SUCCESS : isactive : ${isActive}`); }).catch((err) => { - console.info(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -3327,9 +5725,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.isActive(function (err, isActive) { +avsessionController.isActive(function (err, isActive) { if (err) { - console.info(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`IsActive : SUCCESS : isactive : ${isActive}`); } @@ -3362,10 +5760,10 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.destroy().then(() => { +avsessionController.destroy().then(() => { console.info(`Destroy : SUCCESS `); }).catch((err) => { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -3395,9 +5793,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.destroy(function (err) { +avsessionController.destroy(function (err) { if (err) { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`Destroy : SUCCESS `); } @@ -3431,10 +5829,10 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.getValidCommands.then((validCommands) => { +avsessionController.getValidCommands.then((validCommands) => { console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); }).catch((err) => { - console.info(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -3465,9 +5863,9 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.getValidCommands(function (err, validCommands) { +avsessionController.getValidCommands(function (err, validCommands) { if (err) { - console.info(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); } @@ -3482,7 +5880,7 @@ Sends a control command to the session through the controller. This API uses a p > **NOTE** > -> Before using **sendControlCommand**, the controller must ensure that the AVSession has registered with the corresponding listener. For details about how to register the listener, see [Registering AVSession Listeners](#onplaypausestopplaynextplaypreviousfastforwardrewind10). +> Before using **sendControlCommand**, the controller must ensure that the corresponding listeners are registered for the media session. For details about how to register the listeners, see [on'play'](#onplay10), [on'pause'](#onpause10), and the like. **System capability**: SystemCapability.Multimedia.AVSession.Core @@ -3525,10 +5923,10 @@ let avCommand = {command:'play'}; // let avCommand = {command:'setSpeed', parameter:2.6}; // let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let avCommand = {command:'toggleFavorite', parameter:"false"}; -controller.sendControlCommand(avCommand).then(() => { +avsessionController.sendControlCommand(avCommand).then(() => { console.info(`SendControlCommand successfully`); }).catch((err) => { - console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -3540,7 +5938,7 @@ Sends a control command to the session through the controller. This API uses an > **NOTE** > -> Before using **sendControlCommand**, the controller must ensure that the AVSession has registered with the corresponding listener. For details about how to register the listener, see [Registering AVSession Listeners](#onplaypausestopplaynextplaypreviousfastforwardrewind10). +> Before using **sendControlCommand**, the controller must ensure that the corresponding listeners are registered for the media session. For details about how to register the listeners, see [on'play'](#onplay10), [on'pause'](#onpause10), and the like. **System capability**: SystemCapability.Multimedia.AVSession.Core @@ -3578,11 +5976,11 @@ let avCommand = {command:'play'}; // let avCommand = {command:'setSpeed', parameter:2.6}; // let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let avCommand = {command:'toggleFavorite', parameter:"false"}; -controller.sendControlCommand(avCommand, function (err) { +avsessionController.sendControlCommand(avCommand, function (err) { if (err) { console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`SendControlCommand successfully`); + console.error(`SendControlCommand successfully`); } }); ``` @@ -3603,8 +6001,7 @@ Sends a custom control command to the session through the controller. This API u | args | {[key: string]: any} | Yes | Parameters in key-value pair format carried in the custom control command.| > **NOTE** -> -> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md). +> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md). **Return value** @@ -3632,7 +6029,7 @@ let commandName = "my_command"; let args = { command : "This is my command" } -await controller.sendCommonCommand(commandName, args).catch((err) => { +avsessionController.sendCommonCommand(commandName, args).catch((err) => { console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); }) ``` @@ -3654,8 +6051,7 @@ Sends a custom control command to the session through the controller. This API u | callback | AsyncCallback\ | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | > **NOTE** -> -> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md). +> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md). **Error codes** @@ -3677,94 +6073,88 @@ let commandName = "my_command"; let args = { command : "This is my command" } -controller.sendCommonCommand(commandName, args, (err) => { +avsessionController.sendCommonCommand(commandName, args, (err) => { if(err) { console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); } }) ``` -### on('metadataChange')10+ +### getExtras10+ -on(type: 'metadataChange', filter: Array\ | 'all', callback: (data: AVMetadata) => void) +getExtras(): Promise\<{[key: string]: Object}> -Subscribes to the metadata change event. +Obtains the custom media packet set by the provider. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.AVSession.Core -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'metadataChange'** is reported when the session metadata changes.| -| filter | Array\ | 'all' | Yes | The value **'all'** indicates that any metadata field change will trigger the event, and **Array** indicates that only changes to the listed metadata field will trigger the event.| -| callback | (data: [AVMetadata](#avmetadata10)) => void | Yes | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata. | +| 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 [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600107 | Too many commands or events. | **Example** - ```js -controller.on('metadataChange', 'all', (metadata) => { - console.info(`on metadataChange assetId : ${metadata.assetId}`); -}); - -let metaFilter = ['assetId', 'title', 'description']; -controller.on('metadataChange', metaFilter, (metadata) => { - console.info(`on metadataChange assetId : ${metadata.assetId}`); +let extras = await avsessionController.getExtras().catch((err) => { + console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### on('playbackStateChange')10+ +### getExtras10+ -on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void) +getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void -Subscribes to the playback state change event. +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 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'playbackStateChange'** is reported when the playback state changes.| -| filter | Array\ | 'all' | Yes | The value **'all'** indicates that any playback state field change will trigger the event, and **Array** indicates that only changes to the listed playback state field will trigger the event.| -| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state. | +| 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 [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600107 | Too many commands or events. | **Example** - ```js -controller.on('playbackStateChange', 'all', (playbackState) => { - console.info(`on playbackStateChange state : ${playbackState.state}`); -}); - -let playbackFilter = ['state', 'speed', 'loopMode']; -controller.on('playbackStateChange', playbackFilter, (playbackState) => { - console.info(`on playbackStateChange state : ${playbackState.state}`); +avsessionController.getExtras(function (err, extras) { + if (err) { + console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getExtras : SUCCESS : assetId : ${extras}`); + } }); ``` -### on('sessionEvent')10+ +### on('metadataChange')10+ -on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void +on(type: 'metadataChange', filter: Array\ | 'all', callback: (data: AVMetadata) => void) -Subscribes to session event changes. This API is called by the controller. +Subscribes to metadata change events. **System capability**: SystemCapability.Multimedia.AVSession.Core @@ -3772,8 +6162,9 @@ Subscribes to session event changes. This API is called by the controller. | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'sessionEvent'** is reported when the session event changes.| -| callback | (sessionEvent: string, args: {[key:string]: object}) => void | Yes | Callback used for subscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event. | +| type | string | Yes | Event type. The event **'metadataChange'** is triggered when the session metadata changes.| +| filter | Array\ | 'all' | Yes | The value **'all'** indicates that any metadata field change will trigger the event, and **Array** indicates that only changes to the listed metadata field will trigger the event.| +| callback | (data: [AVMetadata](#avmetadata10)) => void | Yes | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata. | **Error codes** @@ -3787,57 +6178,61 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.on('sessionEvent', (sessionEvent, args) => { - console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); +avsessionController.on('metadataChange', 'all', (metadata) => { + console.info(`on metadataChange assetId : ${metadata.assetId}`); +}); + +let metaFilter = ['assetId', 'title', 'description']; +avsessionController.on('metadataChange', metaFilter, (metadata) => { + console.info(`on metadataChange assetId : ${metadata.assetId}`); }); ``` -### on('queueItemsChange')10+ +### off('metadataChange')10+ -on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void +off(type: 'metadataChange', callback?: (data: AVMetadata) => void) -Subscribes to playlist item changes. This API is called by the controller. +Unsubscribes from metadata change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | -| type | string | Yes | Event type. The event **'queueItemsChange'** is reported when one or more items in the playlist changes.| -| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | Yes | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | +| type | string | Yes | Event type, which is **'metadataChange'** in this case. | +| callback | (data: [AVMetadata](#avmetadata10)) => void | No | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ------------------------------ | +| -------- | ---------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.on('queueItemsChange', (items) => { - console.info(`OnQueueItemsChange, items length is ${items.length}`); -}); +avsessionController.off('metadataChange'); ``` -### on('queueTitleChange')10+ +### on('playbackStateChange')10+ -on(type: 'queueTitleChange', callback: (title: string) => void): void +on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void) -Subscribes to playlist name changes. This API is called by the controller. +Subscribes to playback state change events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The event **'queueTitleChange'** is reported when the playlist name changes.| -| callback | (title: string) => void | Yes | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name. | +| Name | Type | Mandatory| Description | +| --------| -----------|-----|------------| +| type | string | Yes | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.| +| filter | Array\ | 'all' | Yes | The value **'all'** indicates that any playback state field change will trigger the event, and **Array** indicates that only changes to the listed playback state field will trigger the event.| +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.| **Error codes** @@ -3851,49 +6246,51 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.on('queueTitleChange', (title) => { - console.info(`queueTitleChange, title is ${title}`); +avsessionController.on('playbackStateChange', 'all', (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); +}); + +let playbackFilter = ['state', 'speed', 'loopMode']; +avsessionController.on('playbackStateChange', playbackFilter, (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); }); ``` -### on('extrasChange')10+ +### off('playbackStateChange')10+ -on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void +off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) -Subscribes to custom media packet changes. This API is called by the controller. +Unsubscribes from playback state change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'extrasChange'** is reported when the provider sets a custom media packet.| -| callback | (extras: {[key:string]: object}) => void | Yes | Callback used for subscription. The **extras** parameter in the callback indicates the custom media packet set by the provider. This packet is the same as that set in **dispatchSessionEvent**. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'playbackStateChange'** in this case. | +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | No | Callback used for unsubscription. The **state** parameter in the callback indicates the changed playback state.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ------------------------------ | +| -------- | ---------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | -| 401 | Parameter check failed | **Example** ```js -controller.on('extrasChange', (extras) => { - console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); -}); +avsessionController.off('playbackStateChange'); ``` ### on('sessionDestroy')10+ on(type: 'sessionDestroy', callback: () => void) -Subscribes to the session destruction event. +Subscribes to session destruction events. **System capability**: SystemCapability.Multimedia.AVSession.Core @@ -3901,7 +6298,7 @@ Subscribes to the session destruction event. | Name | Type | Mandatory| Description | | -------- | ---------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'sessionDestroy'** is reported when the session is destroyed.| +| type | string | Yes | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.| | callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | **Error codes** @@ -3916,16 +6313,46 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.on('sessionDestroy', () => { +avsessionController.on('sessionDestroy', () => { console.info(`on sessionDestroy : SUCCESS `); }); ``` +### off('sessionDestroy')10+ + +off(type: 'sessionDestroy', callback?: () => void) + +Unsubscribes from session destruction events. This API is called by the controller. + +**System capability**: SystemCapability.Multimedia.AVSession.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------- | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'sessionDestroy'** in this case. | +| callback | () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | + +**Error codes** + +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). + +| ID| Error Message| +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | + +**Example** + +```js +avsessionController.off('sessionDestroy'); +``` + ### on('activeStateChange')10+ on(type: 'activeStateChange', callback: (isActive: boolean) => void) -Subscribes to the session activation state change event. +Subscribes to session activation state change events. **System capability**: SystemCapability.Multimedia.AVSession.Core @@ -3933,7 +6360,7 @@ Subscribes to the session activation state change event. | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'activeStateChange'** is reported when the activation state of the session changes.| +| 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 for subscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the service is activated, and **false** means the opposite. | **Error codes** @@ -3948,96 +6375,94 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.on('activeStateChange', (isActive) => { +avsessionController.on('activeStateChange', (isActive) => { console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); }); ``` -### on('validCommandChange')10+ +### off('activeStateChange')10+ -on(type: 'validCommandChange', callback: (commands: Array\) => void) +off(type: 'activeStateChange', callback?: (isActive: boolean) => void) -Subscribes to valid command changes. +Unsubscribes from session activation state change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'validCommandChange'** is reported when the valid commands supported by the session changes.| -| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. | +| Name | Type | Mandatory| Description | +| -------- | --------------------------- | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'activeStateChange'** in this case. | +| callback | (isActive: boolean) => void | No | Callback used for unsubscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the session is activated, and **false** means the opposite.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ------------------------------ | +| -------- | ---------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.on('validCommandChange', (validCommands) => { - console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`); - console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); -}); +avsessionController.off('activeStateChange'); ``` -### on('outputDeviceChange')10+ +### on('validCommandChange')10+ -on(type: 'outputDeviceChange', callback: (device: OutputDeviceInfo) => void): void +on(type: 'validCommandChange', callback: (commands: Array\) => void) -Subscribes to output device changes. +Subscribes to valid command change events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | Yes | Event type. The event **'outputDeviceChange'** is reported when the output device changes.| -| callback | (device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback used for subscription. The **device** parameter in the callback indicates the output device information. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.| +| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ----------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.on('outputDeviceChange', (device) => { - console.info(`on outputDeviceChange device isRemote : ${device.isRemote}`); +avsessionController.on('validCommandChange', (validCommands) => { + console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`); + console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); }); ``` -### off('metadataChange')10+ +### off('validCommandChange')10+ -off(type: 'metadataChange', callback?: (data: AVMetadata) => void) +off(type: 'validCommandChange', callback?: (commands: Array\) => void) -Unsubscribes from metadata changes. This API is called by the controller. +Unsubscribes from valid command change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | -| type | string | Yes | Event type. The event **'metadataChange'** is reported when the session metadata changes. | -| callback | (data: [AVMetadata](#avmetadata10)) => void | No | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | +| type | string | Yes | Event type, which is **'validCommandChange'** in this case. | +| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | No | Callback used for unsubscription. The **commands** parameter in the callback is a set of valid commands.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). -| ID| Error Message| +| ID| Error Message | | -------- | ---------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | @@ -4045,59 +6470,61 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.off('metadataChange'); +avsessionController.off('validCommandChange'); ``` -### off('playbackStateChange')10+ +### on('outputDeviceChange')10+ -off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) +on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void -Unsubscribes from playback state changes. This API is called by the controller. +Subscribes to output device change events. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | Yes | Event type. The event **'playbackStateChange'** is reported when the playback state changes. | -| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | No | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.| +| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback used for subscription. The **device** parameter in the callback indicates the output device information. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------- | +| -------- | ----------------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.off('playbackStateChange'); +avsessionController.on('outputDeviceChange', (state, device) => { + console.info(`on outputDeviceChange state: ${state}, device : ${device}`); +}); ``` -### off('sessionEvent')10+ +### off('outputDeviceChange')10+ -off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Obejct}) => void): void +off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void -Unsubscribes from session event changes. This API is called by the controller. +Unsubscribes from output device change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'sessionEvent'**. | -| 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.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | +| type | string | Yes | Event type, which is **'outputDeviceChange'** in this case. | +| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). -| ID| Error Message| +| ID | Error Message | | -------- | ---------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | @@ -4105,53 +6532,55 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.off('sessionEvent'); +avsessionController.off('outputDeviceChange'); ``` -### off('queueItemsChange')10+ +### on('sessionEvent')10+ -off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void +on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void -Unsubscribes from playback item changes. This API is called by the controller. +Subscribes to session event change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'queueItemsChange'**. | -| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | No | Callback used for unsubscription. The **items** parameter in the callback indicates the changed items in the playback.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'sessionEvent'** is triggered when the session event changes.| +| callback | (sessionEvent: string, args: {[key:string]: object}) => void | Yes | Callback used for subscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.off('queueItemsChange'); +avsessionController.on('sessionEvent', (sessionEvent, args) => { + console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); +}); ``` -### off('queueTitleChange')10+ +### off('sessionEvent')10+ -off(type: 'queueTitleChange', callback?: (title: string) => void): void +off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void -Unsubscribes from playlist name changes. This API is called by the controller. +Unsubscribes from session event change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'queueTitleChange'**. | -| callback | (title: string) => void | No | Callback used for unsubscription. The **items** parameter in the callback indicates the changed playlist name.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | Yes | Event type, which is **'sessionEvent'** in this case. | +| callback | (sessionEvent: string, args: {[key:string]: Object}) => void | No | Callback used for unsubscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | **Error codes** @@ -4165,54 +6594,55 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.off('queueTitleChange'); +avsessionController.off('sessionEvent'); ``` -### off('extrasChange')10+ +### on('queueItemsChange')10+ -off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void +on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void -Unsubscribes from custom media packet changes. This API is called by the controller. +Subscribes to playlist item change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | -| type | string | Yes | Event type. The value is fixed at **'extrasChange'**. | -| callback | ({[key:string]: Object}) => void | No | Callback used for unsubscription.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | +| type | string | Yes | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes.| +| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | Yes | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------- | -| 6600101 | Session service exception. | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | -| 401 | Parameter check failed | **Example** ```js -controller.off('extrasChange'); +avsessionController.on('queueItemsChange', (items) => { + console.info(`OnQueueItemsChange, items length is ${items.length}`); +}); ``` -### off('sessionDestroy')10+ +### off('queueItemsChange')10+ -off(type: 'sessionDestroy', callback?: () => void) +off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void -Unsubscribes from the session destruction event. This API is called by the controller. +Unsubscribes from playback item change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ---------- | ---- | ----------------------------------------------------- | -| type | string | Yes | Event type. The event **'sessionDestroy'** is reported when the session is destroyed. | -| callback | () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'queueItemsChange'** in this case. | +| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | No | Callback used for unsubscription. The **items** parameter in the callback indicates the changed items in the playlist.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| **Error codes** @@ -4226,59 +6656,61 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.off('sessionDestroy'); +avsessionController.off('queueItemsChange'); ``` -### off('activeStateChange')10+ +### on('queueTitleChange')10+ -off(type: 'activeStateChange', callback?: (isActive: boolean) => void) +on(type: 'queueTitleChange', callback: (title: string) => void): void -Unsubscribes from session activation state changes. This API is called by the controller. +Subscribes to playlist name change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------- | ---- | ----------------------------------------------------- | -| type | string | Yes | Event type. The event **'activeStateChange'** is reported when the session activation state changes. | -| callback | (isActive: boolean) => void | No | Callback used for unsubscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the session is activated, and **false** means the opposite.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | +| type | string | Yes | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes.| +| callback | (title: string) => void | Yes | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). | ID| Error Message| -| -------- | ---------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.off('activeStateChange'); +avsessionController.on('queueTitleChange', (title) => { + console.info(`queueTitleChange, title is ${title}`); +}); ``` -### off('validCommandChange')10+ +### off('queueTitleChange')10+ -off(type: 'validCommandChange', callback?: (commands: Array\) => void) +off(type: 'queueTitleChange', callback?: (title: string) => void): void -Unsubscribes from valid command changes. This API is called by the controller. +Unsubscribes from playlist name change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | -| type | string | Yes | Event type. The event **'validCommandChange'** is reported when the supported commands change. | -| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | No | Callback used for unsubscription. The **commands** parameter in the callback is a set of valid commands.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'queueTitleChange'** in this case. | +| callback | (title: string) => void | No | Callback used for unsubscription. The **items** parameter in the callback indicates the changed playlist name.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). -| ID| Error Message | +| ID| Error Message| | -------- | ---------------- | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | @@ -4286,82 +6718,70 @@ For details about the error codes, see [AVSession Management Error Codes](../err **Example** ```js -controller.off('validCommandChange'); +avsessionController.off('queueTitleChange'); ``` -### off('outputDeviceChange')10+ +### on('extrasChange')10+ -off(type: 'outputDeviceChange', callback?: (device: OutputDeviceInfo) => void): void +on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void -Unsubscribes from output device changes. This API is called by the controller. +Subscribes to custom media packet change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | -| type | string | Yes | Event type. The event **'outputDeviceChange'** is reported when the output device changes. | -| callback | (device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet.| +| callback | (extras: {[key:string]: object}) => void | Yes | Callback used for subscription. The **extras** parameter in the callback indicates the custom media packet set by the provider. This packet is the same as that set in **dispatchSessionEvent**. | **Error codes** For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). -| ID | Error Message | -| -------- | ---------------- | +| ID| Error Message| +| -------- | ------------------------------ | | 6600101 | Session service exception. | | 6600103 | The session controller does not exist. | **Example** ```js -controller.off('outputDeviceChange'); +avsessionController.on('extrasChange', (extras) => { + console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); +}); ``` -## SessionToken - -Describes the information about a session token. - -**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) - -**System capability**: SystemCapability.Multimedia.AVSession.Manager - -**System API**: This is a system API. +### off('extrasChange')10+ -| Name | Type | Mandatory| Description | -| :-------- | :----- | :--- | :----------- | -| sessionId | string | Yes | Session ID. | -| pid | number | Yes | Process ID of the session.| -| uid | number | Yes | User ID. | +off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void -## AVSessionType10+ -Enumerates the session types supported by the session. +Unsubscribes from custom media packet change events. This API is called by the controller. **System capability**: SystemCapability.Multimedia.AVSession.Core -| Name | Type | Description| -| ----- | ------ | ---- | -| audio | string | Audio session.| -| video | string | Video session.| +**Parameters** -## AVSessionDescriptor +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | +| type | string | Yes | Event type, which is **'extrasChange'** in this case. | +| callback | ({[key:string]: Object}) => void | No | Callback used for unsubscription.
The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| -Declares the session descriptor. +**Error codes** -**System capability**: SystemCapability.Multimedia.AVSession.Manager +For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md). -**System API**: This is a system API. +| ID| Error Message| +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | + +**Example** -| Name | Type | Readable| Writable| Description | -| ------------ | ------------------------------------------------------------ | ---- | --------------------------------------------------- | --------------------------------------------------- | -| sessionId | string | Yes | No| Session ID. | -| type | [AVSessionType](#avsessiontype10) | Yes | No | Session type. | -| sessionTag | string | Yes | No | Custom session name. | -| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | No | Information about the application to which the session belongs, including the bundle name and ability name.| -| isActive | boolean | Yes | No | Whether the session is activated. | -| isTopSession | boolean | Yes | No | Whether the session is the top session. | -| outputDevice | [OutputDeviceInfo](#outputdeviceinfo10) | Yes | No | Information about the output device. | +```js +avsessionController.off('extrasChange'); +``` ## AVControlCommandType10+ @@ -4394,142 +6814,20 @@ Describes the command that can be sent to the session. | command | [AVControlCommandType](#avcontrolcommandtype10) | Yes | Command. | | parameter | [LoopMode](#loopmode10) | string | number | No | Parameters carried in the command.| -## AVMetadata10+ - -Describes the media metadata. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Type | Mandatory| Description | -| --------------- |-------------------------| ---- |---------------------------------------------------------------------| -| assetId | string | Yes | Media ID. | -| title | string | No | Title. | -| artist | string | No | Artist. | -| author | string | No | Author. | -| album | string | No | Album name. | -| writer | string | No | Writer. | -| composer | string | No | composer. | -| duration | number | No | Media duration, in ms. | -| mediaImage | image.PixelMap | string | No | Pixel map or image path (local path or network path) of the image. | -| publishDate | Date | No | Release date. | -| subtitle | string | No | Subtitle. | -| description | string | No | Media description. | -| lyric | string | No | Lyric file path (local path or network path).| -| previousAssetId | string | No | ID of the previous media asset. | -| nextAssetId | string | No | ID of the next media asset. | - -## AVMediaDescription10+ - -Describes the attributes related to the media metadata of the playlist. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Type | Mandatory | Description | -| ------------ | ----------------------- | ---- | ----------------------- | -| mediaId | string | Yes | Media ID of the playlist. | -| title | string | No | Name of the playlist. | -| subtitle | string | No | Subname of the playlist. | -| description | string | No | Description of the playlist. | -| icon | image.PixelMap | No | Pixel map of the image of the playlist.| -| iconUri | string | No | Path of the image of the playlist.| -| extras | {[key: string]: any} | No | Additional fields of the playlist. | -| mediaUri | string | No | Media URI. | - -## AVQueueItem10+ - -Describes the attributes of an item in the playlist. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Type | Mandatory| Description | -| ------------ | ------------------------------------------ | ---- | --------------------------- | -| itemId | number | Yes | ID of an item in the playlist. | -| description | [AVMediaDescription](#avmediadescription10) | Yes | Media metadata of the item in the playlist. | - -## AVPlaybackState10+ - -Describes the information related to the media playback state. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Type | Mandatory| Description | -| ------------ | ------------------------------------- | ---- | ------- | -| state | [PlaybackState](#playbackstate) | No | Playback state.| -| speed | number | No | Playback speed.| -| position | [PlaybackPosition](#playbackposition) | No | Playback position.| -| bufferedTime | number | No | Buffered time.| -| loopMode | [LoopMode](#loopmode10) | No | Loop mode.| -| isFavorite | boolean | No | Whether the media asset is favorited.| -| activeItemId10+ | number | No | ID of the item that is being played.| -| extras10+ | {[key: string]: Object} | No | Custom media data.| - -## PlaybackPosition10+ - -Describes the information related to the playback position. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Type | Mandatory| Description | -| ----------- | ------ | ---- | ------------------ | -| elapsedTime | number | Yes | Elapsed time, in ms.| -| updateTime | number | Yes | Updated time, in ms.| - -## OutputDeviceInfo10+ - -Describes the information related to the output device. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Type | Mandatory| Description | -| ---------- | -------------- | ---- | ---------------------- | -| isRemote | boolean | Yes | Whether the device is connected. | -| audioDeviceId | Array | Yes | IDs of output devices. | -| deviceName | Array | Yes | Names of output devices. | - -## PlaybackState10+ - -Enumerates the media playback states. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Value | Description | -| --------------------------- | ---- | ----------- | -| PLAYBACK_STATE_INITIAL | 0 | Initial. | -| PLAYBACK_STATE_PREPARE | 1 | Preparing. | -| PLAYBACK_STATE_PLAY | 2 | Playing. | -| PLAYBACK_STATE_PAUSE | 3 | Paused. | -| PLAYBACK_STATE_FAST_FORWARD | 4 | Fast-forwarding. | -| PLAYBACK_STATE_REWIND | 5 | Rewinding. | -| PLAYBACK_STATE_STOP | 6 | Stopped. | - - -## LoopMode10+ - -Enumerates the loop modes of media playback. - -**System capability**: SystemCapability.Multimedia.AVSession.Core - -| Name | Value | Description | -| ------------------ | ---- | -------- | -| LOOP_MODE_SEQUENCE | 0 | Sequential playback.| -| LOOP_MODE_SINGLE | 1 | Single loop.| -| LOOP_MODE_LIST | 2 | Playlist loop.| -| LOOP_MODE_SHUFFLE | 3 | Shuffle.| - ## AVSessionErrorCode10+ Enumerates the error codes used in the media session. **System capability**: SystemCapability.Multimedia.AVSession.Core -| Name | Value | Description | -| ------------------------------ | ------- | ------------------------------- | -| ERR_CODE_SERVICE_EXCEPTION | 6600101 | Session service exception. | -| ERR_CODE_SESSION_NOT_EXIST | 6600102 | The session does not exist. | -| ERR_CODE_CONTROLLER_NOT_EXIST | 6600103 | The session controller does not exist. | -| ERR_CODE_REMOTE_CONNECTION_ERR | 6600104 | The remote session connection failed. | -| ERR_CODE_COMMAND_INVALID | 6600105 | Invalid session command. | -| ERR_CODE_SESSION_INACTIVE | 6600106 | The session is not activated. | -| ERR_CODE_MESSAGE_OVERLOAD | 6600107 | Too many commands or events. | - - +| Name | Value | Description | +| -------------------------------------- | ------- | ------------------------------- | +| ERR_CODE_SERVICE_EXCEPTION | 6600101 | Session service exception. | +| ERR_CODE_SESSION_NOT_EXIST | 6600102 | The session does not exist. | +| ERR_CODE_CONTROLLER_NOT_EXIST | 6600103 | The session controller does not exist. | +| ERR_CODE_REMOTE_CONNECTION_ERR | 6600104 | The remote session connection failed. | +| ERR_CODE_COMMAND_INVALID | 6600105 | Invalid session command. | +| ERR_CODE_SESSION_INACTIVE | 6600106 | The session is not activated. | +| ERR_CODE_MESSAGE_OVERLOAD | 6600107 | Too many commands or events. | +| ERR_CODE_DEVICE_CONNECTION_FAILED | 6600108 | Device connecting failed. | +| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST | 6600109 | The remote connection is not established. | diff --git a/en/application-dev/reference/apis/js-apis-camera.md b/en/application-dev/reference/apis/js-apis-camera.md index 56a63d8d5620ba09928caffd6de17861f500b2cb..d9ec7a942cc86ce8d331eb8920b81111e1c8c8c4 100644 --- a/en/application-dev/reference/apis/js-apis-camera.md +++ b/en/application-dev/reference/apis/js-apis-camera.md @@ -170,6 +170,7 @@ Obtains the output capability supported by a camera. This API returns the result **Example** ```js +let cameras = cameraManager.getSupportedCameras(); let cameraDevice = cameras[0]; let cameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice); @@ -581,6 +582,160 @@ cameraManager.on('cameraMute', (err, curMuetd) => { }) ``` +### isPrelaunchSupported + +isPrelaunchSupported(camera: CameraDevice): boolean + +Checks whether a camera supports prelaunch. This API is called in prior to **setPrelaunchConfig**. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------- | ---- | --------- | +| camera | [CameraDevice](#cameradevice) | Yes| Camera object.| + +**Return value** + +| Type| Description| +| -------- | --------------- | +| boolean | Returns whether the camera supports prelaunch. The value **true** means that the camera supports prelaunch, and **false** means the opposite.| + +**Error codes** + +For details about the error codes, see [CameraErrorCode](#cameraerrorcode). + +| ID | Error Message | +| --------------- | --------------- | +| 7400101 | Parameter missing or parameter type incorrect. | + +**Example** + +```js +this.cameraManager = camera.getCameraManager(globalThis.abilityContext); +let cameras = this.cameraManager.getSupportedCameras() +if(this.cameraManager.isPrelaunchSupported(cameras[0])) { + this.cameraManager.setPrelaunchConfig({cameraDevice: cameras[0]}); +} +``` + +### setPrelaunchConfig + +setPrelaunchConfig(prelaunchConfig: PrelaunchConfig): void + +**System API**: This is a system API. + +**Required permissions**: ohos.permission.CAMERA + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------- | ---- | --------- | +| prelaunchConfig | [PrelaunchConfig](#prelaunchconfig) | Yes| Prelaunch configuration.| + +**Error codes** + +For details about the error codes, see [CameraErrorCode](#cameraerrorcode). + +| ID | Error Message | +| --------------- | --------------- | +| 7400101 | Parameter missing or parameter type incorrect. | +| 7400102 | Operation not allow. | + +**Example** + +```js +this.cameraManager = camera.getCameraManager(globalThis.abilityContext); +let cameras = this.cameraManager.getSupportedCameras() +if(this.cameraManager.isPrelaunchSupported(cameras[0])) { + try { + this.cameraManager.setPrelaunchConfig({cameraDevice: cameras[0]}); + } catch (error) { + console.error(`catch error: Code: ${error.code}, message: ${error.message}`); + } +} +``` + +### prelaunch + +prelaunch(): void + +Prelaunches the camera. This API is called when the camera application is started after a user clicks the system camera icon. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Example** + +```js +this.cameraManager = camera.getCameraManager(globalThis.abilityContext); +try { + this.cameraManager.prelaunch(); +} catch (error) { + console.error(`catch error: Code: ${error.code}, message: ${error.message}`); +} +``` + +### createDeferredPreviewOutput + +createDeferredPreviewOutput(profile: Profile): PreviewOutput + +Creates a deferred **PreviewOutput** instance and adds it to the data stream instead of a common **PreviewOutput** instance during stream configuration. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------- | ---- | --------- | +| profile | [Profile](#profile) | Yes| Configuration file of the camera preview stream.| + +**Return value** + +| Type| Description| +| -------- | --------------- | +| [PreviewOutput](#previewoutput) | Returns a **PreviewOutput** instance.| + +**Error codes** + +For details about the error codes, see [CameraErrorCode](#cameraerrorcode). + +| ID | Error Message | +| --------------- | --------------- | +| 7400101 | Parameter missing or parameter type incorrect. | + +**Example** + +```js +function getDeferredPreviewOutput(context: Context, previewProfile: camera.Profile): Promise { + const cameraManager = camera.getCameraManager(context); + const output: Promise = cameraManager.createDeferredPreviewOutput(previewProfile); + return output; +} +``` + +## PrelaunchConfig + +Defines the camera prelaunch configuration. + +Currently, the configuration is used for sensor-level prelaunch. It will be used for stream-level prelaunch in a later version. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +| Name | Type | Mandatory | Description | +| ------ | ----------------------------- | -------------- | ---------- | +| cameraDevice | [CameraDevice](#cameradevice) | Yes | Camera object.| + ## CameraStatusInfo Describes the camera status information. @@ -835,7 +990,7 @@ cameraInput.close().then(() => { ### on('error') -on(type: 'error', camera:CameraDevice, callback: ErrorCallback\): void +on(type: 'error', camera:CameraDevice, callback: ErrorCallback): void Listens for **CameraInput** errors. This API uses a callback to return the result. @@ -847,12 +1002,11 @@ Listens for **CameraInput** errors. This API uses a callback to return the resul | -------- | -------------------------------- | --- | ------------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **CameraInput** instance is created. This event is triggered and the result is returned when an error occurs on the camera. For example, if the device is unavailable or a conflict occurs, the error information is returned.| | cameraDevice | [CameraDevice](#cameradevice) | Yes | **CameraDevice** object.| -| callback | ErrorCallback\ | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | +| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | **Example** ```js -let cameraDevice = cameras[0]; cameraInput.on('error', cameraDevice, (error) => { console.log(`Camera input error code: ${error.code}`); }) @@ -883,7 +1037,7 @@ Enumerates the exposure modes. | EXPOSURE_MODE_AUTO | 1 | Auto exposure. The metering point can be set by calling [setMeteringPoint](#setmeteringpoint).| | EXPOSURE_MODE_CONTINUOUS_AUTO | 2 | Continuous auto exposure. The metering point cannot be set.| - ## FocusMode +## FocusMode Enumerates the focus modes. @@ -2288,7 +2442,7 @@ captureSession.on('focusStateChange', (err, focusState) => { ### on('error') -on(type: 'error', callback: ErrorCallback\): void +on(type: 'error', callback: ErrorCallback): void Listens for **CaptureSession** errors. This API uses a callback to return the errors. @@ -2299,7 +2453,7 @@ Listens for **CaptureSession** errors. This API uses a callback to return the er | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------------------- | ---- | ------------------------------ | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a session is created. This event is triggered and the error message is returned when an error occurs during the calling of a session-related API such as **beginConfig()**, **commitConfig()**, and **addInput**.| -| callback | ErrorCallback\ | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | +| callback | ErrorCallback| Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | **Example** @@ -2547,7 +2701,7 @@ previewOutput.on('frameEnd', () => { ### on('error') -on(type: 'error', callback: ErrorCallback\): void +on(type: 'error', callback: ErrorCallback): void Listens for **PreviewOutput** errors. This API uses a callback to return the errors. @@ -2558,7 +2712,7 @@ Listens for **PreviewOutput** errors. This API uses a callback to return the err | Name | Type | Mandatory| Description | | -------- | --------------| ---- | ------------------------ | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **previewOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the use of a preview-related API such as **start()** or **release()**.| -| callback | ErrorCallback\ | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | +| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | **Example** @@ -2568,6 +2722,49 @@ previewOutput.on('error', (previewOutputError) => { }) ``` +### addDeferredSurface + +addDeferredSurface(surfaceId: string): void + +Adds a surface for delayed preview. This API can run after **session.commitConfig()** is used to commit the configuration for a stream and **session.start()** is used to start the stream. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------| ---- | ------------------------ | +| surfaceId | string | Yes| Surface ID, which is obtained from **[XComponent](../arkui-ts/ts-basic-components-xcomponent.md)**.| + +**Error codes** + +For details about the error codes, see [CameraErrorCode](#cameraerrorcode). + +| ID | Error Message | +| --------------- | --------------- | +| 7400101 | Parameter missing or parameter type incorrect | + +**Example** + +```js +function async preview(context: Context, cameraInfo: camera.Device, previewProfile: camera.Profile, photoProfile: camera.Profile, surfaceId: string): Promise { + const cameraManager: camera.CameraManager = camera.getCameraManager(context); + const cameraInput camera.CameraInput = await cameraManager.createCameraInput(cameraInfo) + const previewOutput: camera.PreviewOutput = await cameraManager.createDeferredPreviewOutput(previewProfile); + const photoOutput: camera.PhotoOutput = await cameraManager.createPhotoOutput(photoProfile); + const session: camera.CaptureSession = await this.mCameraManager.createCaptureSession(); + await session.beginConfig(); + await session.addInput(cameraInput); + await session.addOutput(previewOutput); + await session.addOutput(photoOutput); + await session.commitConfig(); + await session.start(); + await previewOutput.addDeferredSurface(surfaceId); +} +``` + ## ImageRotation Enumerates the image rotation angles. @@ -2772,6 +2969,17 @@ For details about the error codes, see [CameraErrorCode](#cameraerrorcode). **Example** ```js +let captureLocation = { + latitude: 0, + longitude: 0, + altitude: 0, +} +let settings = { + quality: camera.QualityLevel.QUALITY_LEVEL_LOW, + rotation: camera.ImageRotation.ROTATION_0, + location: captureLocation, + mirror: false +} photoOutput.capture(settings).then(() => { console.log('Promise returned to indicate that photo capture request success.'); }).catch((err) => { @@ -2938,7 +3146,7 @@ photoOutput.on('captureEnd', (err, captureEndInfo) => { ### on('error') -on(type: 'error', callback: ErrorCallback\): void +on(type: 'error', callback: ErrorCallback): void Listens for **PhotoOutput** errors. This API uses a callback to return the errors. @@ -2949,7 +3157,7 @@ Listens for **PhotoOutput** errors. This API uses a callback to return the error | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | ----------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **photoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a photographing-related API.| -| callback | ErrorCallback\ | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | +| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | **Example** @@ -2959,6 +3167,153 @@ photoOutput.on('error', (error) => { }) ``` +### isQuickThumbnailSupported + +isQuickThumbnailSupported(): boolean + +Checks whether the quick thumbnail feature is supported. + +This API takes effect after **CaptureSession.addOutput** and **CaptureSession.addInput** and before **CaptureSession.commitConfig**. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Return value** + +| Type| Description| +| --------- | ------ | +| boolean | Returns whether the quick thumbnail feature is supported. The value **true** means that the quick thumbnail feature is supported, and **false** means the opposite.| + +**Error codes** + +For details about the error codes, see [CameraErrorCode](#cameraerrorcode). + +| ID | Error Message | +| --------------- | --------------- | +| 7400101 | Parameter missing or parameter type incorrect | + +**Example** + +```js +this.cameraManager = camera.getCameraManager(globalThis.abilityContext); +let cameras = this.cameraManager.getSupportedCameras() +// Create a CaptureSession instance. +this.captureSession = await this.cameraManager.createCaptureSession() +// Start configuration for the session. +await this.captureSession.beginConfig() +// Add a CameraInput instance to the session. +this.mCameraInput = await this.cameraManager.createCameraInput(cameras[0]) +await this.cameraInput.open() +await this.captureSession.addInput(this.cameraInput) +// Add a PhotoOutput instance to the session. +this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId) +await this.captureSession.addOutput(this.photoOutPut) + +boolean isSupported = this.photoOutPut.isQuickThumbnailSupported() +``` + +### enableQuickThumbnail + +enableQuickThumbnail(enabled: boolean): void + +Enables or disables the quick thumbnail feature. + +This API takes effect after **CaptureSession.addOutput** and **CaptureSession.addInput** and before **CaptureSession.commitConfig**. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ----------------------------------- | +| enabled | boolean | Yes | Whether to enable the quick thumbnail feature. The value **true** means to enable the quick thumbnail feature, and **false** means the opposite.| + +**Error codes** + +For details about the error codes, see [CameraErrorCode](#cameraerrorcode). + +| ID | Error Message | +| --------------- | --------------- | +| 7400101 | Parameter missing or parameter type incorrect | + +**Example** + +```js +this.cameraManager = camera.getCameraManager(globalThis.abilityContext); +let cameras = this.cameraManager.getSupportedCameras() +// Create a CaptureSession instance. +this.captureSession = await this.cameraManager.createCaptureSession() +// Start configuration for the session. +await this.captureSession.beginConfig() +// Add a CameraInput instance to the session. +this.cameraInput = await this.cameraManager.createCameraInput(cameras[0]) +await this.cameraInput.open() +await this.captureSession.addInput(this.cameraInput) +// Add a PhotoOutput instance to the session. +this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId) +await this.captureSession.addOutput(this.photoOutPut) +boolean isSupported = this.photoOutPut.isQuickThumbnailSupported() +if (isSupported) { + // Enable the quick thumbnail feature. + this.photoOutPut.enableQuickThumbnail(true) +} +``` + +### on('quickThumbnail') + +on(type: 'quickThumbnail', callback: AsyncCallback\): void + +Listens for the quick thumbnail output events. + +The listening takes effect after **enableQuickThumbnail(true)** is called. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Multimedia.Camera.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------- | ---- | ----------------------------------- | +| type | string | Yes | Event type. The value is fixed at **'quickThumbnail'**.| +| callback | AsyncCallback\<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise that returns a **PixelMap** instance.| + +**Example** + +```js +import camera from '@ohos.multimedia.camera' + +this.cameraManager = camera.getCameraManager(globalThis.abilityContext); +let cameras = this.cameraManager.getSupportedCameras() +// Create a CaptureSession instance. +this.captureSession = await this.cameraManager.createCaptureSession() +// Start configuration for the session. +await this.captureSession.beginConfig() +// Add a CameraInput instance to the session. +this.cameraInput = await this.cameraManager.createCameraInput(cameras[0]) +await this.cameraInput.open() +await this.captureSession.addInput(this.cameraInput) +// Add a PhotoOutput instance to the session. +this.photoOutPut = await this.cameraManager.createPhotoOutput(photoProfile, surfaceId) +await this.captureSession.addOutput(this.photoOutPut) +boolean isSupported = this.photoOutPut.isQuickThumbnailSupported() +if (isSupported) { + // Enable the quick thumbnail feature. + this.photoOutPut.enableQuickThumbnail(true) +} +this.photoOutPut.on('quickThumbnail', (err, pixelmap) => { + if (err || pixelmap === undefined) { + Logger.error(this.tag, 'photoOutPut on thumbnail failed ') + return + } + // Display or save the PixelMap instance. + this.showOrSavePicture(pixelmap) +}) +``` + ## FrameShutterInfo Defines the frame shutter information. @@ -3217,7 +3572,7 @@ videoOutput.on('frameEnd', () => { ### on('error') -on(type: 'error', callback: ErrorCallback\): void +on(type: 'error', callback: ErrorCallback): void Listens for errors that occur during video recording. This API uses a callback to return the result. @@ -3228,7 +3583,7 @@ Listens for errors that occur during video recording. This API uses a callback t | Name | Type | Mandatory| Description | | -------- | ----------- | ---- | -------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **videoOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a recording-related API such as **start()** and **release()**.| -| callback | Callback\ | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | +| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | **Example** @@ -3385,7 +3740,7 @@ metadataOutput.on('metadataObjectsAvailable', (err, metadataObjectArr) => { ### on('error') -on(type: 'error', callback: ErrorCallback\): void +on(type: 'error', callback: ErrorCallback): void Listens for metadata errors. This API uses an asynchronous callback to return the result. @@ -3396,7 +3751,7 @@ Listens for metadata errors. This API uses an asynchronous callback to return th | Name | Type | Mandatory| Description | | -------- | ------------- | ---- | --------------------------------------- | | type | string | Yes | Event type. The value is fixed at **'error'**. The event can be listened for when a **metadataOutput** instance is created. This event is triggered and the corresponding error message is returned when an error occurs during the calling of a metadata-related API such as **start()** and **release()**.| -| callback | Callback\ | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | +| callback | ErrorCallback | Yes | Callback used to return an error code defined in [CameraErrorCode](#cameraerrorcode). | **Example** diff --git a/en/application-dev/reference/apis/js-apis-freeInstall.md b/en/application-dev/reference/apis/js-apis-freeInstall.md index 160d0ebbcef331046e6bb52fb84971aba1cbe5b2..eae0860a65ecb6fd771d48c22b3f3eb109619843 100644 --- a/en/application-dev/reference/apis/js-apis-freeInstall.md +++ b/en/application-dev/reference/apis/js-apis-freeInstall.md @@ -18,8 +18,8 @@ import freeInstall from '@ohos.bundle.freeInstall'; | Permission | Permission Level | Description | | ------------------------------------------ | ------------ | ------------------ | -| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.| -| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall bundles. | +| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all aplications.| +| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall other applications except enterprise applications, including enterprise InHouse, mobile device management (MDM), and Normal applications. | For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels). ## UpgradeFlag diff --git a/en/application-dev/reference/apis/js-apis-image.md b/en/application-dev/reference/apis/js-apis-image.md index 24c8730727b438c9efd3bfd4244fa55a5a605add..e09c5fd1a1b2fc826611889232ccaf2ad8717d43 100644 --- a/en/application-dev/reference/apis/js-apis-image.md +++ b/en/application-dev/reference/apis/js-apis-image.md @@ -883,7 +883,7 @@ async function Demo() { getColorSpace(): colorSpaceManager.ColorSpaceManager -Obtains the color space of this image +Obtains the color space of this image. **System capability**: SystemCapability.Multimedia.Image.Core diff --git a/en/application-dev/reference/apis/js-apis-installer.md b/en/application-dev/reference/apis/js-apis-installer.md index b75aca7a1e9286773798a75ebb4f0514dd9ac6f8..3e31435e0f3030b1e659c038a9e11062c4316836 100644 --- a/en/application-dev/reference/apis/js-apis-installer.md +++ b/en/application-dev/reference/apis/js-apis-installer.md @@ -16,7 +16,11 @@ import installer from '@ohos.bundle.installer'; | Permission | Permission Level | Description | | ------------------------------ | ----------- | ---------------- | -| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall bundles.| +| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall other applications except enterprise applications, including enterprise InHouse, mobile device management (MDM), and Normal applications.| +| ohos.permission.INSTALL_ENTERPRISE_BUNDLE | system_core | Permission to install enterprise InHouse applications.| +| ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE | system_core | Permission to install enterprise MDM applications.| +| ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE | system_core | Permission to install enterprise Normal applications.| + For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels). diff --git a/en/application-dev/reference/apis/js-apis-media.md b/en/application-dev/reference/apis/js-apis-media.md index 4f290e8cc883e736d7aeacd4bebd26940c699217..5654300a33ef42db7686a4c3de3ff541f4bdb8a0 100644 --- a/en/application-dev/reference/apis/js-apis-media.md +++ b/en/application-dev/reference/apis/js-apis-media.md @@ -310,19 +310,18 @@ Enumerates the media description keys. **System capability**: SystemCapability.Multimedia.Media.Core -| Name | Value | Description | -| ----------------------------- | --------------- | ------------------------------------------------------------ | -| MD_KEY_TRACK_INDEX | 'track_index' | Track index, which is a number. | -| MD_KEY_TRACK_TYPE | 'track_type' | Track type, which is a number. For details, see [MediaType](#mediatype8).| -| MD_KEY_CODEC_MIME | 'codec_mime' | Codec MIME type, which is a string. | -| MD_KEY_DURATION | 'duration' | Media duration, which is a number, in units of ms. | -| MD_KEY_BITRATE | 'bitrate' | Bit rate, which is a number, in units of bit/s. | -| MD_KEY_WIDTH | 'width' | Video width, which is a number, in units of pixel. | -| MD_KEY_HEIGHT | 'height' | Video height, which is a number, in units of pixel. | -| MD_KEY_FRAME_RATE | 'frame_rate' | Video frame rate, which is a number, in units of 100 fps.| -| MD_KEY_AUD_CHANNEL_COUNT | 'channel_count' | Number of audio channels, which is a number. | -| MD_KEY_AUD_SAMPLE_RATE | 'sample_rate' | Sampling rate, which is a number, in units of Hz. | -| MD_KEY_LANGUAGE10+ | "language" | Language, which is a string. | +| Name | Value | Description | +| ------------------------ | --------------- | ------------------------------------------------------------ | +| MD_KEY_TRACK_INDEX | 'track_index' | Track index, which is a number. | +| MD_KEY_TRACK_TYPE | 'track_type' | Track type, which is a number. For details, see [MediaType](#mediatype8).| +| MD_KEY_CODEC_MIME | 'codec_mime' | Codec MIME type, which is a string. | +| MD_KEY_DURATION | 'duration' | Media duration, which is a number, in units of ms. | +| MD_KEY_BITRATE | 'bitrate' | Bit rate, which is a number, in units of bit/s. | +| MD_KEY_WIDTH | 'width' | Video width, which is a number, in units of pixel. | +| MD_KEY_HEIGHT | 'height' | Video height, which is a number, in units of pixel. | +| MD_KEY_FRAME_RATE | 'frame_rate' | Video frame rate, which is a number, in units of 100 fps.| +| MD_KEY_AUD_CHANNEL_COUNT | 'channel_count' | Number of audio channels, which is a number. | +| MD_KEY_AUD_SAMPLE_RATE | 'sample_rate' | Sampling rate, which is a number, in units of Hz. | ## BufferingInfoType8+ @@ -1001,124 +1000,6 @@ for (let i = 0; i < arrayDescription.length; i++) { } ``` -### selectTrack10+ - -selectTrack(index: number): void - -Selects an audio track. This API can be called only when the AVPlayer is in the prepared state. You can listen for the [trackChange event](#trackchange_on) to determine whether the API calling takes effect. - -**System capability**: SystemCapability.Multimedia.Media.AVPlayer - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | ------------------------------------------------------------ | -| index | number | Yes | Track ID, which can be obtained by calling [getTrackDescription](#avplayer_gettrackdescription).| - -**Example** - -```js -let index = 2 -avPlayer.selectTrack(index) -``` - -### deselectTrack10+ - -deselectTrack(index: number): void - -Deselects an audio track. The default audio track will be used after the audio track is deselected. This API can be called only when the AVPlayer is in the prepared state. You can listen for the [trackChange event](#trackchange_on) to determine whether the API calling takes effect. - -**System capability**: SystemCapability.Multimedia.Media.AVPlayer - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | ------------------------------------------------------------ | -| index | number | Yes | Track ID. You can obtain the ID of the current track by calling [getCurrentTrack](#avplayer_getcurrenttrack).| - -**Example** - -```js -let index = 2 -avPlayer.deselectTrack(index) -``` - -### getCurrentTrack10+ - -getCurrentTrack(trackType: MediaType, callback: AsyncCallback\): void - -Obtains the ID of the current track. This API uses an asynchronous callback to return the result. It can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. - -**System capability**: SystemCapability.Multimedia.Media.AVPlayer - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ----------------------- | ---- | ------------------------------------------------------------ | -| trackType | [MediaType](#mediatype) | Yes | Enumerates the media types. | -| callback | AsyncCallback\ | Yes | Callback used to return the current track. If **-1** is returned, no track for the specified media type exists.| - -**Error codes** - -For details about the error codes, see [Media Error Codes](../errorcodes/errorcode-media.md). - -| ID| Error Message | -| -------- | ------------------------------------------ | -| 5400102 | Operation not allowed. Return by callback. | - -**Example** - -```js -let mediaType = media.MediaType.MEDIA_TYPE_AUD; -let trackIndex = null; - -avPlayer.getCurrentTrack(mediaType, (err, index) => { - if (err == null) { - console.info('getCurrentTrack success'); - trackIndex = index; - } else { - console.error('getCurrentTrack failed and error is ' + err.message); - } -}); -``` - -### getCurrentTrack10+ - -getCurrentTrack(trackType: MediaType): Promise\ - -Obtains the ID of the current track. This API uses a promise to return the result. It can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. - -**System capability**: SystemCapability.Multimedia.Media.AVPlayer - -**Return value** - -| Type | Description | -| ---------------- | ------------------------------------------------------------ | -| trackType | [MediaType](#mediatype) | -| Promise\| Promise used to return the current track. If **-1** is returned, no track for the specified media type exists.| - -**Error codes** - -For details about the error codes, see [Media Error Codes](../errorcodes/errorcode-media.md). - -| ID| Error Message | -| -------- | ----------------------------------------- | -| 5400102 | Operation not allowed. Return by promise. | - -**Example** - -```js -let mediaType = media.MediaType.MEDIA_TYPE_AUD; -let trackIndex = null; - -avPlayer.getCurrentTrack(mediaType).then((index) => { - console.info('getCurrentTrack success'); - trackIndex = index; -}).catch((err) => { - console.error('getCurrentTrack failed and catch error is ' + err.message); -}); -``` - ### seek9+ seek(timeMs: number, mode?:SeekMode): void @@ -1725,49 +1606,6 @@ Unsubscribes from the audio interruption event. avPlayer.off('audioInterrupt') ``` -### on('trackChange')10+ - -on(type: 'trackChange', callback: (index: number, isSelect: boolean) => void): void; - -Subscribes to track changes, which are triggered by calling **selectTrack** or **deselectTrack**. - -**System capability**: SystemCapability.Multimedia.Media.AVPlayer - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | -------- | ---- | ----------------------------------------------------- | -| type | string | Yes | Event type, which is **'trackChange'** in this case.| -| callback | function | Yes | Callback invoked when the event is triggered. | - -**Example** - -```js -avPlayer.on('trackChange', (index: number, isSelect: boolean) => { - console.info('trackChange success, and index is:' + index + ', isSelect is :' + isSelect) -}) -``` - -### off('trackChange')10+ - -off(type: 'trackChange'): void - -Unsubscribes from track changes - -**System capability**: SystemCapability.Multimedia.Media.AVPlayer - -**Parameters** - -| Name| Type | Mandatory| Description | -| ------ | ------ | ---- | --------------------------------------------------------- | -| type | string | Yes | Event type, which is **'trackChange'** in this case.| - -**Example** - -```js -avPlayer.off('trackChange') -``` - ## AVPlayerState9+ Enumerates the states of the [AVPlayer](#avplayer9). Your application can proactively obtain the AVPlayer state through the **state** attribute or obtain the reported AVPlayer state by subscribing to the [stateChange](#stateChange_on) event. For details about the rules for state transition, see [Audio Playback](../../media/using-avplayer-for-playback.md). @@ -2680,6 +2518,8 @@ Enumerates the AVRecorder states. You can obtain the state through the **state** Describes the audio and video recording parameters. +The **audioSourceType** and **videoSourceType** parameters are used to distinguish audio-only recording, video-only recording, and audio and video recording. For audio-only recording, set only **audioSourceType**. For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. + **System capability**: SystemCapability.Multimedia.Media.AVRecorder | Name | Type | Mandatory| Description | @@ -2691,8 +2531,6 @@ Describes the audio and video recording parameters. | rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. | | location | [Location](#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. | -The **audioSourceType** and **videoSourceType** parameters are used to distinguish audio-only recording, video-only recording, and audio and video recording. For audio-only recording, set only **audioSourceType**. For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. - ## AVRecorderProfile9+ Describes the audio and video recording profile. @@ -3517,13 +3355,15 @@ Enumerates the video recording states. You can obtain the state through the **st Describes the video recording parameters. +The **audioSourceType** and **videoSourceType** parameters are used to distinguish video-only recording from audio and video recording. (For audio-only recording recording, use **[AVRecorder](#avrecorder9)** or **[AudioRecorder](#audiorecorderdeprecated)**.) For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. + **System capability**: SystemCapability.Multimedia.Media.VideoRecorder **System API**: This is a system API. | Name | Type | Mandatory| Description | | --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | -| audioSourceType | [AudioSourceType](#audiosourcetype9) | Yes | Type of the audio source for video recording. | +| audioSourceType | [AudioSourceType](#audiosourcetype9) | No | Type of the audio source for video recording. This parameter is mandatory for audio recording. | | videoSourceType | [VideoSourceType](#videosourcetype9) | Yes | Type of the video source for video recording. | | profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | | rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. | @@ -3540,10 +3380,10 @@ Describes the video recording profile. | Name | Type | Mandatory| Description | | ---------------- | -------------------------------------------- | ---- | ---------------- | -| audioBitrate | number | Yes | Audio encoding bit rate.| -| audioChannels | number | Yes | Number of audio channels.| -| audioCodec | [CodecMimeType](#codecmimetype8) | Yes | Audio encoding format. | -| audioSampleRate | number | Yes | Audio sampling rate. | +| audioBitrate | number | No | Audio encoding bit rate. This parameter is mandatory for audio recording.| +| audioChannels | number | No | Number of audio channels. This parameter is mandatory for audio recording.| +| audioCodec | [CodecMimeType](#codecmimetype8) | No | Audio encoding format. This parameter is mandatory for audio recording. | +| audioSampleRate | number | No | Audio sampling rate. This parameter is mandatory for audio recording. | | fileFormat | [ContainerFormatType](#containerformattype8) | Yes | Container format of a file.| | videoBitrate | number | Yes | Video encoding bit rate.| | videoCodec | [CodecMimeType](#codecmimetype8) | Yes | Video encoding format. | diff --git a/en/application-dev/reference/apis/js-apis-sensor.md b/en/application-dev/reference/apis/js-apis-sensor.md index e2058f68ea5d50766c17fa4381fbf6453aa19b4e..bf7ca4b511fe27cfb4f4d60084bcc40032d058c2 100644 --- a/en/application-dev/reference/apis/js-apis-sensor.md +++ b/en/application-dev/reference/apis/js-apis-sensor.md @@ -24,7 +24,7 @@ Subscribes to data of the color sensor. **System API**: This is a system API. -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -63,7 +63,7 @@ Subscribes to data of the Sodium Adsorption Ratio (SAR) sensor. **System API**: This is a system API. -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -109,7 +109,7 @@ Subscribes to data of the acceleration sensor. | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -149,7 +149,7 @@ Subscribes to data of the uncalibrated acceleration sensor. | callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -190,7 +190,7 @@ Subscribes to data of the ambient light sensor. | callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to report the sensor data, which is a **LightResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -226,7 +226,7 @@ Subscribes to data of the ambient temperature sensor. | callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -262,7 +262,7 @@ Subscribes to data of the barometer sensor. | callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to report the sensor data, which is a **BarometerResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -298,7 +298,7 @@ Subscribes to data of the gravity sensor. | callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to report the sensor data, which is a **GravityResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -338,7 +338,7 @@ Subscribes to data of the gyroscope sensor. | callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -379,7 +379,7 @@ Subscribes to data of the uncalibrated gyroscope sensor. | callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -420,7 +420,7 @@ Subscribes to data of the Hall effect sensor. | callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to report the sensor data, which is a **HallResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -458,7 +458,7 @@ Subscribes to data of the heart rate sensor. | callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to report the sensor data, which is a **HeartRateResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -494,7 +494,7 @@ Subscribes to data of the humidity sensor. | callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to report the sensor data, which is a **HumidityResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -533,7 +533,7 @@ Subscribes to data of the linear acceleration sensor. | callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -571,7 +571,7 @@ Subscribes to data of the magnetic field sensor. | callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -609,7 +609,7 @@ Subscribes to data of the uncalibrated magnetic field sensor. | callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -642,7 +642,7 @@ Subscribes to data of the orientation sensor. **System capability**: SystemCapability.Sensors.Sensor -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -682,7 +682,7 @@ Subscribes to data of the pedometer sensor. **System capability**: SystemCapability.Sensors.Sensor -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -729,7 +729,7 @@ Subscribes to data of the pedometer detection sensor. | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -765,7 +765,7 @@ Subscribes to data of the proximity sensor. | callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to report the sensor data, which is a **ProximityResponse** object. | | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -802,7 +802,7 @@ Subscribes to data of the rotation vector sensor. | callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to report the sensor data, which is a **RotationVectorResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -842,7 +842,7 @@ Subscribes to data of the significant motion sensor. | callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -879,7 +879,7 @@ Subscribes to data of the wear detection sensor. | callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to report the sensor data, which is a **WearDetectionResponse** object.| | options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -918,7 +918,7 @@ Obtains data of the acceleration sensor once. | type | [SensorId](#sensorid9).ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**. | | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -957,7 +957,7 @@ Obtains data of the uncalibrated acceleration sensor once. | type | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. | | callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -997,7 +997,7 @@ Obtains data of the ambient light sensor once. | type | [SensorId](#sensorid9).AMBIENT_LIGHT | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**. | | callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to report the sensor data, which is a **LightResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1032,7 +1032,7 @@ Obtains data of the temperature sensor once. | type | [SensorId](#sensorid9).AMBIENT_TEMPERATURE | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**. | | callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1067,7 +1067,7 @@ Obtains data of the barometer sensor once. | type | [SensorId](#sensorid9).BAROMETER | Yes | Sensor type. The value is fixed at **SensorId.BAROMETER**. | | callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to report the sensor data, which is a **BarometerResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1102,7 +1102,7 @@ Obtains data of the gravity sensor once. | type | [SensorId](#sensorid9).GRAVITY | Yes | Sensor type. The value is fixed at **SensorId.GRAVITY**. | | callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to report the sensor data, which is a **GravityResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1141,7 +1141,7 @@ Obtains to data of the gyroscope sensor once. | type | [SensorId](#sensorid9).GYROSCOPE | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE**. | | callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1182,7 +1182,7 @@ Obtains data of the uncalibrated gyroscope sensor once. | type | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**. | | callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1222,7 +1222,7 @@ Obtains data of the Hall effect sensor once. | type | [SensorId](#sensorid9).HALL | Yes | Sensor type. The value is fixed at **SensorId.HALL**. | | callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to report the sensor data, which is a **HallResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1259,7 +1259,7 @@ Obtains data of the heart rate sensor once. | type | [SensorId](#sensorid9).HEART_RATE | Yes | Sensor type. The value is fixed at **SensorId.HEART_RATE**. | | callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to report the sensor data, which is a **HeartRateResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1294,7 +1294,7 @@ Obtains data of the humidity sensor once. | type | [SensorId](#sensorid9).HUMIDITY | Yes | Sensor type. The value is fixed at **SensorId.HUMIDITY**. | | callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to report the sensor data, which is a **HumidityResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1331,7 +1331,7 @@ Obtains data of the linear acceleration sensor once. | type | [SensorId](#sensorid9).LINEAR_ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**. | | callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1368,7 +1368,7 @@ Obtains data of the magnetic field sensor once. | type | [SensorId](#sensorid9).MAGNETIC_FIELD | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**. | | callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1405,7 +1405,7 @@ Obtains data of the uncalibrated magnetic field sensor once. | type | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.| | callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1445,7 +1445,7 @@ Obtains data of the orientation sensor once. | type | [SensorId](#sensorid9).ORIENTATION | Yes | Sensor type. The value is fixed at **SensorId.ORIENTATION**. | | callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to report the sensor data, which is a **OrientationResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1484,7 +1484,7 @@ Obtains data of the pedometer sensor once. | type | [SensorId](#sensorid9).PEDOMETER | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER**. | | callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1521,7 +1521,7 @@ Obtains data of the pedometer sensor once. | type | [SensorId](#sensorid9).PEDOMETER_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**. | | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1556,7 +1556,7 @@ Obtains data of the proximity sensor once. | type | [SensorId](#sensorid9).PROXIMITY | Yes | Sensor type. The value is fixed at **SensorId.PROXIMITY**. | | callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to report the sensor data, which is a **ProximityResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1591,7 +1591,7 @@ Obtains data of the rotation vector sensor once. | type | [SensorId](#sensorid9).ROTATION_VECTOR | Yes | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**. | | callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to report the sensor data, which is a **RotationVectorResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1629,7 +1629,7 @@ Obtains data of the significant motion sensor once. | type | [SensorId](#sensorid9).SIGNIFICANT_MOTION | Yes | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**. | | callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1664,7 +1664,7 @@ Obtains data of the wear detection sensor once. | type | [SensorId](#sensorid9).WEAR_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**. | | callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to report the sensor data, which is a **WearDetectionResponse** object.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -2596,7 +2596,7 @@ Obtains the geomagnetic field of a geographic location at a certain time. This A | timeMillis | number | Yes | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.| | callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | Yes | Callback used to return the geomagnetic field. | -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md). @@ -2647,7 +2647,7 @@ Obtains the geomagnetic field of a geographic location at a certain time. This A | ---------------------------------------------------------- | -------------- | | Promise<[GeomagneticResponse](#geomagneticresponse)> | Promise used to return the geomagnetic field.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md). @@ -2692,7 +2692,7 @@ Obtains the altitude based on the atmospheric pressure. This API uses an asynchr | currentPressure | number | Yes | Specified atmospheric pressure, in hPa.| | callback | AsyncCallback<number> | Yes | Callback used to return the altitude, in meters. | -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md). @@ -2739,7 +2739,7 @@ Obtains the altitude based on the atmospheric pressure. This API uses a promise | --------------------- | ------------------------------------ | | Promise<number> | Promise used to return the altitude, in meters.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md). @@ -2779,7 +2779,7 @@ Obtains the magnetic dip based on the inclination matrix. This API uses an async | inclinationMatrix | Array<number> | Yes | Inclination matrix. | | callback | AsyncCallback<number> | Yes | Callback used to return the magnetic dip, in radians.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md). @@ -2829,7 +2829,7 @@ Obtains the magnetic dip based on the inclination matrix. This API uses a promis | --------------------- | ---------------------------- | | Promise<number> | Promise used to return the magnetic dip, in radians.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md). @@ -2875,7 +2875,7 @@ Obtains the angle change between two rotation matrices. This API uses an asynchr | preRotationMatrix | Array<number> | Yes | The other rotation matrix. | | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the angle change around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md). @@ -2936,7 +2936,7 @@ Obtains the angle change between two rotation matrices. This API uses a promise | ---------------------------------- | --------------------------------- | | Promise<Array<number>> | Promise used to return the angle change around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md). @@ -2990,7 +2990,7 @@ Obtains the rotation matrix from a rotation vector. This API uses an asynchronou | rotationVector | Array<number> | Yes | Rotation vector.| | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3037,7 +3037,7 @@ Obtains the rotation matrix from a rotation vector. This API uses a promise to r | ---------------------------------- | -------------- | | Promise<Array<number>> | Promise used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3132,7 +3132,7 @@ Transforms a rotation vector based on the coordinate system. This API uses a pro | ---------------------------------- | ---------------------- | | Promise<Array<number>> | Promise used to return the rotation vector after being transformed.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.transformRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3177,7 +3177,7 @@ Obtains the quaternion from a rotation vector. This API uses an asynchronous cal | rotationVector | Array<number> | Yes | Rotation vector.| | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the quaternion. | -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md). @@ -3224,7 +3224,7 @@ Obtains the quaternion from a rotation vector. This API uses a promise to return | ---------------------------------- | ------------ | | Promise<Array<number>> | Promise used to return the quaternion.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md). @@ -3265,7 +3265,7 @@ Obtains the device direction based on the rotation matrix. This API uses an asyn | rotationMatrix | Array<number> | Yes | Rotation matrix. | | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation angle around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md). @@ -3319,7 +3319,7 @@ Obtains the device direction based on the rotation matrix. This API uses a promi | ---------------------------------- | --------------------------------- | | Promise<Array<number>> | Promise used to return the rotation angle around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md). @@ -3365,7 +3365,7 @@ Obtains the rotation matrix based on a gravity vector and geomagnetic vector. Th | geomagnetic | Array<number> | Yes | Geomagnetic vector.| | callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes | Callback used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3387,7 +3387,7 @@ try { console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); }) } catch (error) { -console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); + console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3412,7 +3412,7 @@ Obtains the rotation matrix based on a gravity vector and geomagnetic vector. Th | ------------------------------------------------------------ | -------------- | | Promise<[RotationMatrixResponse](#rotationmatrixresponse)> | Promise used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3451,7 +3451,7 @@ Obtains information about all sensors on the device. This API uses an asynchrono | -------- | ---------------------------------------------- | ---- | ---------------- | | callback | AsyncCallback<Array<[Sensor](#sensor9)>> | Yes | Callback used to return the sensor list.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md). @@ -3491,7 +3491,7 @@ Obtains information about all sensors on the device. This API uses a promise to | ------- | ---------------------------------------- | ---- | ---------------- | | promise | Promise<Array<[Sensor](#sensor9)>> | Yes | Promise used to return the sensor list.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md). @@ -3530,7 +3530,7 @@ Obtains information about the sensor of a specific type. This API uses an asynch | type | [SensorId](#sensorid9) | Yes | Sensor type. | | callback | AsyncCallback<[Sensor](#sensor9)> | Yes | Callback used to return the sensor information.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md). @@ -3574,7 +3574,7 @@ Obtains information about the sensor of a specific type. This API uses a promise | ------- | --------------------------------- | ---- | ---------------- | | promise | Promise<[Sensor](#sensor9)> | Yes | Promise used to return the sensor information.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md). @@ -3612,6 +3612,8 @@ Enumerates the sensor types. | HALL | 10 | Hall effect sensor. | | PROXIMITY | 12 | Proximity sensor. | | HUMIDITY | 13 | Humidity sensor. | +| COLOR10+ | 14 | Color sensor.
System API: This is a system API. | +| SAR10+ | 15 | Sodium Adsorption Ratio (SAR) sensor.
System API: This is a system API.| | ORIENTATION | 256 | Orientation sensor. | | GRAVITY | 257 | Gravity sensor. | | LINEAR_ACCELEROMETER | 258 | Linear acceleration sensor. | @@ -4912,7 +4914,7 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| **Example** - + ```ts sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function (data) { console.info('Succeeded in invoking once. Steps: ' + data.steps); @@ -6211,7 +6213,7 @@ promise.then((data) => { }).catch((reason) => { console.info("Succeeded in getting promise::catch", reason); }) -``` + ``` ## sensor.createQuaternion(deprecated) @@ -6410,4 +6412,4 @@ promise.then((data) => { }).catch((err) => { console.info(`Failed to get promise.`); }) - ``` +``` diff --git a/en/application-dev/reference/apis/js-apis-xml.md b/en/application-dev/reference/apis/js-apis-xml.md index 9554f5b07dd9f131c81c7ef8e30df9813cc303e9..4b75afc59d5190bddcef2ceda8d17014a8bd7d87 100644 --- a/en/application-dev/reference/apis/js-apis-xml.md +++ b/en/application-dev/reference/apis/js-apis-xml.md @@ -49,7 +49,7 @@ console.log(view1) // setAttributes(name: string, value: string): void -Sets an attribute. +Writes an attribute and its value. **System capability**: SystemCapability.Utils.Lang @@ -57,8 +57,8 @@ Sets an attribute. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | --------------- | -| name | string | Yes | Key of the attribute. | -| value | string | Yes | Value of the attribute.| +| name | string | Yes | Attribute to write. | +| value | string | Yes | Attribute value to write.| **Example** @@ -114,7 +114,7 @@ console.log(view1) // setDeclaration(): void -Sets a declaration. +Writes an XML file declaration. **System capability**: SystemCapability.Utils.Lang @@ -237,7 +237,7 @@ console.log(JSON.stringify(view1)) //\r\n< setComment(text: string): void -Sets the comment. +Writes a comment. **System capability**: SystemCapability.Utils.Lang @@ -245,7 +245,7 @@ Sets the comment. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------------------- | -| text | string | Yes | Comment to set.| +| text | string | Yes | Comment to write.| **Example** @@ -268,7 +268,7 @@ console.log(view1) //' setCDATA(text: string): void -Sets CDATA attributes. +Writes CDATA data. **System capability**: SystemCapability.Utils.Lang @@ -276,7 +276,7 @@ Sets CDATA attributes. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ----------------- | -| text | string | Yes | CDATA attribute to set.| +| text | string | Yes | CDATA data to write.| **Example** @@ -299,7 +299,7 @@ console.log(view1) //''' setText(text: string): void -Sets **Text**. +Writes a tag value. **System capability**: SystemCapability.Utils.Lang @@ -307,7 +307,7 @@ Sets **Text**. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ---------------- | -| text | string | Yes | Content of the **Text** to set.| +| text | string | Yes | Tag value to write, which is the content of the **text** attribute.| **Example** @@ -333,7 +333,7 @@ console.log(view1) // 'Happy1' setDocType(text: string): void -Sets **DocType**. +Writes a document type. **System capability**: SystemCapability.Utils.Lang @@ -341,7 +341,7 @@ Sets **DocType**. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------- | -| text | string | Yes | Content of **DocType** to set.| +| text | string | Yes | Content of **DocType** to write.| **Example** @@ -473,11 +473,11 @@ Defines the XML parsing options. | Name | Type | Mandatory| Description | | ------------------------------ | ------------------------------------------------------------ | ---- | --------------------------------------- | -| supportDoctype | boolean | No | Whether to ignore **Doctype**. The default value is **false**.| -| ignoreNameSpace | boolean | No | Whether to ignore **Namespace**. The default value is **false**. | -| tagValueCallbackFunction | (name: string, value: string) => boolean | No | Callback used to return **tagValue**. The default value is **null**. | -| attributeValueCallbackFunction | (name: string, value: string) => boolean | No | Callback used to return **attributeValue**. The default value is **null**. | -| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo)) => boolean | No | Callback used to return **tokenValue**. The default value is **null**. | +| supportDoctype | boolean | No | Whether to ignore the document type. The default value is **false**, indicating that the document type is parsed.| +| ignoreNameSpace | boolean | No | Whether to ignore the namespace. The default value is **false**, indicating that the namespace is parsed.| +| tagValueCallbackFunction | (name: string, value: string) => boolean | No | Callback used to return **tagValue** for parsing the tag and tag value. The default value is **null**, indicating that the tag and tag value are not parsed. | +| attributeValueCallbackFunction | (name: string, value: string) => boolean | No | Callback used to return **attributeValue** for parsing the attribute and attribute value. The default value is **null**, indicating that the attribute and attribute value are not parsed.| +| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo)) => boolean | No | Callback used to return **tokenValue** for parsing the [EventType](#eventtype) and [ParseInfo](#parseinfo) attributes. The default value is **null**, indicating that the **EventType** and **ParseInfo** attribute are not parsed.| ## ParseInfo @@ -923,20 +923,20 @@ console.log(str); ## EventType -Enumerates the events. +Enumerates the event types. **System capability**: SystemCapability.Utils.Lang | Name | Value | Description | | ---------------- | ---- | --------------------- | -| START_DOCUMENT | 0 | Indicates a start document event. | -| END_DOCUMENT | 1 | Indicates an end document event. | -| START_TAG | 2 | Indicates a start tag event. | -| END_TAG | 3 | Indicates an end tag event. | -| TEXT | 4 | Indicates a text event. | -| CDSECT | 5 | Indicates a CDATA section event. | -| COMMENT | 6 | Indicates an XML comment event. | -| DOCDECL | 7 | Indicates an XML document type declaration event.| -| INSTRUCTION | 8 | Indicates an XML processing instruction event.| -| ENTITY_REFERENCE | 9 | Indicates an entity reference event. | -| WHITESPACE | 10 | Indicates a whitespace character event. | +| START_DOCUMENT | 0 | Start document event. | +| END_DOCUMENT | 1 | End document event. | +| START_TAG | 2 | Start tag event. | +| END_TAG | 3 | End tag event. | +| TEXT | 4 | Text event. | +| CDSECT | 5 | CDATA section event. | +| COMMENT | 6 | XML comment event. | +| DOCDECL | 7 | XML document type declaration event. | +| INSTRUCTION | 8 | XML processing instruction event. | +| ENTITY_REFERENCE | 9 | Entity reference event. | +| WHITESPACE | 10 | Whitespace character event. | diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.8.6/changelogs-multimedia.md b/en/release-notes/changelogs/OpenHarmony_4.0.8.6/changelogs-multimedia.md new file mode 100644 index 0000000000000000000000000000000000000000..7a0392510d07d52e02f813832b541c583c9faa6c --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.8.6/changelogs-multimedia.md @@ -0,0 +1,17 @@ +# Multimedia Subsystem Changelog + +## cl.multimedia.1 Reference Paths Changed for the Audio/Video Encapsulation and Decapsulation Header Files + +| Header File | Original Reference Path | New Reference Path | +| ------------------------------- | ------------------------------------- | ------------------------------------- | +| native_avmuxer.h | | | +| native_avdemuxer.h | | | +| native_avsource.h | | | + +**Change Impact** + +Applications that use the involved APIs may have compatibility issues. + +**Adaptation Guide** + +Modify the reference paths when referencing the encapsulation and decapsulation header files. diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.9.1/changelogs-bundlemanager.md b/en/release-notes/changelogs/OpenHarmony_4.0.9.1/changelogs-bundlemanager.md index d548acfdd27a44bb15e909ef61d4ce14853f2957..81e6a2850eba67f2e2ad8adc568037f19babc0c5 100644 --- a/en/release-notes/changelogs/OpenHarmony_4.0.9.1/changelogs-bundlemanager.md +++ b/en/release-notes/changelogs/OpenHarmony_4.0.9.1/changelogs-bundlemanager.md @@ -14,7 +14,6 @@ The bottom-layer implementation is changed. The result value of **getAllBundleIn **Adaptation Guide** If your application uses **getAllBundleInfo** in **@ohos.bundle.d.ts**, replace it with **getAllBundleInfo** in **@ohos.bundle.bundleManager.d.ts**. For details about how to use the new API, see [API Reference](../../../application-dev/reference/apis/js-apis-bundleManager.md#bundlemanagergetallbundleinfo). - ```ets import bundleManager from '@ohos.bundle.bundleManager'; ``` @@ -34,7 +33,6 @@ The bottom-layer implementation is changed. The result value of **getAllApplicat **Adaptation Guide** If your application uses **getAllApplicationInfo** in **@ohos.bundle.d.ts**, replace it with **getAllApplicationInfo** in **@ohos.bundle.bundleManager.d.ts**. For details about how to use the new API, see [API Reference](../../../application-dev/reference/apis/js-apis-bundleManager.md#bundlemanagergetallapplicationinfo). - ```ets import bundleManager from '@ohos.bundle.bundleManager'; ``` @@ -113,13 +111,13 @@ To use **getAdditionalInfo**, import the **bundleManager** module. import bundleManager form '@ohos.bundle.bundleManager' ``` -## cl.bundlemanager.7 proxyDatas under Schema Renamed proxyData +## cl.bundlemanager.7 proxyDatas Renamed proxyData in the module.json5 File **proxyDatas** is renamed **proxyData**. **Change Impact** -After an update to the new image version, **proxyDatas** is renamed **proxyData**. Currently **proxyDatas** can still be used, but it will be deprecated soon. You are advised to replace **proxyDatas** with **proxyData** as soon as possible. +After an update to the new SDK version, **proxyDatas** is **renamed proxyData**. If your application is not adapted, the build will fail. **Key API/Component Changes** @@ -127,4 +125,5 @@ After an update to the new image version, **proxyDatas** is renamed **proxyData* **Adaptation Guide** -Replace **proxyDatas** with **proxyData**. \ No newline at end of file +Replace **proxyDatas** with **proxyData**. The content of **proxyDatas** does not need to be changed. + diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-bundlemanager.md b/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-bundlemanager.md new file mode 100644 index 0000000000000000000000000000000000000000..ce84729d285eaf27d0db2db7e050992c23b610fa --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-bundlemanager.md @@ -0,0 +1,16 @@ +# Bundle Management Subsystem Changelog +## cl.bundlemanager.1 schema in the module.json File Changed + +In the **module.json** file, the **name** attributes of the **module**, **ability**, and **extensionAbility** fields must start with a letter and contain only letters, digits, underscores (_), and dots (.). + +**Change Impact** + +After an update to the new SDK version, the build fails if the **name** attributes of these fields do not meet the preceding requirements. + +**Key API/Component Changes** + +In the **module.json** file, the **name** attributes of the **module**, **ability**, and **extensionAbility** fields must start with a letter and contain only letters, digits, underscores (_), and dots (.). + +**Adaptation Guide** + +Modify the **name** attributes for these fields accordingly to the new requirements. \ No newline at end of file diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-media.md b/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-media.md new file mode 100644 index 0000000000000000000000000000000000000000..dd8e4f564113ffd39ae4c8c745fad59366addcef --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-media.md @@ -0,0 +1,23 @@ +# Media Subsystem ChangeLog + +## cl.media.1 Playback APIs Changed + +The APIs related to audio track switching are deleted. + +**Change Impact** + +These APIs are unavailable. + +**Key API/Component Changes** + +The deleted APIs are as follows: + +| Class | API | +| -------------- | ------------------------------------------------------------ | +| Media.Core | MD_KEY_LANGUAGE | +| Media.AVPlayer | selectTrack(index: number): void | +| Media.AVPlayer | deselectTrack(index: number): void | +| Media.AVPlayer | getCurrentTrack(trackType: MediaType, callback: AsyncCallback\): void | +| Media.AVPlayer | getCurrentTrack(trackType: MediaType): Promise\ | +| Media.AVPlayer | on(type: 'trackChange', callback: (index: number, isSelect: boolean) => void): void; | +| Media.AVPlayer | off(type: 'trackChange'): void | diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-multimedia.md b/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-multimedia.md new file mode 100644 index 0000000000000000000000000000000000000000..fd52f4b4e8bd35704f53bcec7cfbea60423e3889 --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.9.3/changelogs-multimedia.md @@ -0,0 +1,29 @@ +# Multimedia Subsystem Changelog + +## cl.multimedia.1 Deleted content from getAudioEffectInfoArray + +The input parameter **content** is deleted from **getAudioEffectInfoArray**. + +**Change Impact** + +Applications that use the involved APIs may have compatibility issues. + +**Key API/Component Changes** + +Before change: + + ```js +getAudioEffectInfoArray(content: ContentType, usage: StreamUsage, callback: AsyncCallback): void; +getAudioEffectInfoArray(content: ContentType, usage: StreamUsage): Promise; + ``` + +After change: + + ```js +getAudioEffectInfoArray(usage: StreamUsage, callback: AsyncCallback): void; +getAudioEffectInfoArray(usage: StreamUsage): Promise; + ``` + +**Adaptation Guide** + +When calling this API, pass in only the input parameter **usage**. If **getAudioEffectInfoArray** is used in your application code, delete the **content** parameter.