提交 6d9cf064 编写于 作者: Z zhangkai269

js-api-avsession arkts整改

Signed-off-by: Nzhangkai269 <zhangkai269@huawei.com>
上级 ba0e70f1
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
## 导入模块 ## 导入模块
```js ```ts
import avSession from '@ohos.multimedia.avsession'; import avSession from '@ohos.multimedia.avsession';
``` ```
...@@ -50,19 +50,19 @@ createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AV ...@@ -50,19 +50,19 @@ createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AV
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let sessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio").then((data) => { avSession.createAVSession(context, tag, "audio").then((data: avSession.AVSession) => {
currentAVSession = data; currentAVSession = data;
sessionId = currentAVSession.sessionId; sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -94,15 +94,15 @@ createAVSession(context: Context, tag: string, type: AVSessionType, callback: As ...@@ -94,15 +94,15 @@ createAVSession(context: Context, tag: string, type: AVSessionType, callback: As
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let sessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -140,15 +140,17 @@ getAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>> ...@@ -140,15 +140,17 @@ getAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>>
**示例:** **示例:**
```js ```ts
avSession.getAllSessionDescriptors().then((descriptors) => { import { BusinessError } from '@ohos.base';
avSession.getAllSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor) => {
console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
if(descriptors.length > 0 ){ if(descriptors.length > 0 ){
console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
} }
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -181,8 +183,10 @@ getAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDesc ...@@ -181,8 +183,10 @@ getAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDesc
**示例:** **示例:**
```js ```ts
avSession.getAllSessionDescriptors(function (err, descriptors) { import { BusinessError } from '@ohos.base';
avSession.getAllSessionDescriptors((err: BusinessError, descriptors: avSession.AVSessionDescriptor) => {
if (err) { if (err) {
console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -230,8 +234,10 @@ getHistoricalSessionDescriptors(maxSize?: number): Promise\<Array\<Readonly\<AVS ...@@ -230,8 +234,10 @@ getHistoricalSessionDescriptors(maxSize?: number): Promise\<Array\<Readonly\<AVS
**示例:** **示例:**
```js ```ts
avSession.getHistoricalSessionDescriptors().then((descriptors) => { import { BusinessError } from '@ohos.base';
avSession.getHistoricalSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor) => {
console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
if(descriptors.length > 0 ){ if(descriptors.length > 0 ){
console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
...@@ -240,7 +246,7 @@ avSession.getHistoricalSessionDescriptors().then((descriptors) => { ...@@ -240,7 +246,7 @@ avSession.getHistoricalSessionDescriptors().then((descriptors) => {
console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`); console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`);
console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`);
} }
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -274,8 +280,10 @@ getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\<Array\ ...@@ -274,8 +280,10 @@ getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\<Array\
**示例:** **示例:**
```js ```ts
avSession.getHistoricalSessionDescriptors(1, function (err, descriptors) { import { BusinessError } from '@ohos.base';
avSession.getHistoricalSessionDescriptors(1, (err: BusinessError, descriptors: avSession.AVSessionDescriptor) => {
if (err) { if (err) {
console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -326,15 +334,15 @@ createController(sessionId: string): Promise\<AVSessionController> ...@@ -326,15 +334,15 @@ createController(sessionId: string): Promise\<AVSessionController>
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let sessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -344,11 +352,11 @@ avSession.createAVSession(context, tag, "audio", function (err, data) { ...@@ -344,11 +352,11 @@ avSession.createAVSession(context, tag, "audio", function (err, data) {
} }
}); });
let currentAVcontroller; let currentAVcontroller: avSession.AVSessionController;
avSession.createController(sessionId).then((avcontroller) => { avSession.createController(sessionId).then((avcontroller: avSession.AVSessionController) => {
currentAVcontroller = avcontroller; currentAVcontroller = avcontroller;
console.info('CreateController : SUCCESS '); console.info('CreateController : SUCCESS ');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -382,15 +390,15 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController ...@@ -382,15 +390,15 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let sessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -400,8 +408,8 @@ avSession.createAVSession(context, tag, "audio", function (err, data) { ...@@ -400,8 +408,8 @@ avSession.createAVSession(context, tag, "audio", function (err, data) {
} }
}); });
let currentAVcontroller; let currentAVcontroller: avSession.AVSessionController;
avSession.createController(sessionId, function (err, avcontroller) { avSession.createController(sessionId, (err: BusinessError, avcontroller: avSession.AVSessionController) => {
if (err) { if (err) {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -449,22 +457,23 @@ castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDe ...@@ -449,22 +457,23 @@ castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDe
**示例:** **示例:**
```js ```ts
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
import { BusinessError } from '@ohos.base';
let audioManager = audio.getAudioManager(); let audioManager = audio.getAudioManager();
let audioRoutingManager = audioManager.getRoutingManager(); let audioRoutingManager = audioManager.getRoutingManager();
let audioDevices; let audioDevices: audio.AudioDeviceDescriptors;
await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
audioDevices = data; audioDevices = data;
console.info(`Promise returned to indicate that the device list is obtained.`); console.info(`Promise returned to indicate that the device list is obtained.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
avSession.castAudio('all', audioDevices).then(() => { avSession.castAudio('all', audioDevices).then(() => {
console.info(`CreateController : SUCCESS`); console.info(`CreateController : SUCCESS`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -502,20 +511,21 @@ castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDe ...@@ -502,20 +511,21 @@ castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDe
**示例:** **示例:**
```js ```ts
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
import { BusinessError } from '@ohos.base';
let audioManager = audio.getAudioManager(); let audioManager = audio.getAudioManager();
let audioRoutingManager = audioManager.getRoutingManager(); let audioRoutingManager = audioManager.getRoutingManager();
let audioDevices; let audioDevices: audio.AudioDeviceDescriptors;
await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
audioDevices = data; audioDevices = data;
console.info(`Promise returned to indicate that the device list is obtained.`); console.info(`Promise returned to indicate that the device list is obtained.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
avSession.castAudio('all', audioDevices, function (err) { avSession.castAudio('all', audioDevices, (err: BusinessError) => {
if (err) { if (err) {
console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -568,8 +578,8 @@ on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): voi ...@@ -568,8 +578,8 @@ on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): voi
**示例:** **示例:**
```js ```ts
avSession.on('sessionCreate', (descriptor) => { avSession.on('sessionCreate', (descriptor: avSession.AVSessionDescriptor) => {
console.info(`on sessionCreate : isActive : ${descriptor.isActive}`); console.info(`on sessionCreate : isActive : ${descriptor.isActive}`);
console.info(`on sessionCreate : type : ${descriptor.type}`); console.info(`on sessionCreate : type : ${descriptor.type}`);
console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`); console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`);
...@@ -605,8 +615,8 @@ on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): vo ...@@ -605,8 +615,8 @@ on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): vo
**示例:** **示例:**
```js ```ts
avSession.on('sessionDestroy', (descriptor) => { avSession.on('sessionDestroy', (descriptor: avSession.AVSessionDescriptor) => {
console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`); console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`);
console.info(`on sessionDestroy : type : ${descriptor.type}`); console.info(`on sessionDestroy : type : ${descriptor.type}`);
console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`); console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`);
...@@ -641,8 +651,8 @@ on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): ...@@ -641,8 +651,8 @@ on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void):
**示例:** **示例:**
```js ```ts
avSession.on('topSessionChange', (descriptor) => { avSession.on('topSessionChange', (descriptor: avSession.AVSessionDescriptor) => {
console.info(`on topSessionChange : isActive : ${descriptor.isActive}`); console.info(`on topSessionChange : isActive : ${descriptor.isActive}`);
console.info(`on topSessionChange : type : ${descriptor.type}`); console.info(`on topSessionChange : type : ${descriptor.type}`);
console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`); console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`);
...@@ -677,7 +687,7 @@ off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): v ...@@ -677,7 +687,7 @@ off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): v
**示例:** **示例:**
```js ```ts
avSession.off('sessionCreate'); avSession.off('sessionCreate');
``` ```
...@@ -709,7 +719,7 @@ off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): ...@@ -709,7 +719,7 @@ off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void):
**示例:** **示例:**
```js ```ts
avSession.off('sessionDestroy'); avSession.off('sessionDestroy');
``` ```
...@@ -741,7 +751,7 @@ off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void) ...@@ -741,7 +751,7 @@ off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void)
**示例:** **示例:**
```js ```ts
avSession.off('topSessionChange'); avSession.off('topSessionChange');
``` ```
...@@ -771,7 +781,7 @@ on(type: 'sessionServiceDie', callback: () => void): void ...@@ -771,7 +781,7 @@ on(type: 'sessionServiceDie', callback: () => void): void
**示例:** **示例:**
```js ```ts
avSession.on('sessionServiceDie', () => { avSession.on('sessionServiceDie', () => {
console.info(`on sessionServiceDie : session is Died `); console.info(`on sessionServiceDie : session is Died `);
}); });
...@@ -803,7 +813,7 @@ off(type: 'sessionServiceDie', callback?: () => void): void ...@@ -803,7 +813,7 @@ off(type: 'sessionServiceDie', callback?: () => void): void
**示例:** **示例:**
```js ```ts
avSession.off('sessionServiceDie'); avSession.off('sessionServiceDie');
``` ```
...@@ -836,11 +846,14 @@ sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void ...@@ -836,11 +846,14 @@ sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let keyItem = {code:0x49, pressedTime:2, deviceId:0}; import keyEvent from '@ohos.multimodalInput.keyEvent';
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}; import { BusinessError } from '@ohos.base';
let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0};
let event: keyEvent.KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avSession.sendSystemAVKeyEvent(event, function (err) { avSession.sendSystemAVKeyEvent(event, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -883,14 +896,16 @@ sendSystemAVKeyEvent(event: KeyEvent): Promise\<void> ...@@ -883,14 +896,16 @@ sendSystemAVKeyEvent(event: KeyEvent): Promise\<void>
**示例:** **示例:**
```js ```ts
import keyEvent from '@ohos.multimodalInput.keyEvent';
import { BusinessError } from '@ohos.base';
let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let keyItem: keyEvent.Key = {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}; let event: keyEvent.KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avSession.sendSystemAVKeyEvent(event).then(() => { avSession.sendSystemAVKeyEvent(event).then(() => {
console.info(`SendSystemAVKeyEvent Successfully`); console.info(`SendSystemAVKeyEvent Successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -925,7 +940,9 @@ sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<voi ...@@ -925,7 +940,9 @@ sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<voi
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
let cmd : avSession.AVControlCommandType = 'play'; let cmd : avSession.AVControlCommandType = 'play';
// let cmd : avSession.AVControlCommandType = 'pause'; // let cmd : avSession.AVControlCommandType = 'pause';
// let cmd : avSession.AVControlCommandType = 'stop'; // let cmd : avSession.AVControlCommandType = 'stop';
...@@ -933,7 +950,7 @@ let cmd : avSession.AVControlCommandType = 'play'; ...@@ -933,7 +950,7 @@ let cmd : avSession.AVControlCommandType = 'play';
// let cmd : avSession.AVControlCommandType = 'playPrevious'; // let cmd : avSession.AVControlCommandType = 'playPrevious';
// let cmd : avSession.AVControlCommandType = 'fastForward'; // let cmd : avSession.AVControlCommandType = 'fastForward';
// let cmd : avSession.AVControlCommandType = 'rewind'; // let cmd : avSession.AVControlCommandType = 'rewind';
let avcommand = {command:cmd}; let avcommand: avSession.AVControlCommand = {command:cmd};
// let cmd : avSession.AVControlCommandType = 'seek'; // let cmd : avSession.AVControlCommandType = 'seek';
// let avcommand = {command:cmd, parameter:10}; // let avcommand = {command:cmd, parameter:10};
// let cmd : avSession.AVControlCommandType = 'setSpeed'; // let cmd : avSession.AVControlCommandType = 'setSpeed';
...@@ -942,7 +959,7 @@ let avcommand = {command:cmd}; ...@@ -942,7 +959,7 @@ let avcommand = {command:cmd};
// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let cmd : avSession.AVControlCommandType = 'toggleFavorite'; // let cmd : avSession.AVControlCommandType = 'toggleFavorite';
// let avcommand = {command:cmd, parameter:"false"}; // let avcommand = {command:cmd, parameter:"false"};
avSession.sendSystemControlCommand(avcommand, function (err) { avSession.sendSystemControlCommand(avcommand, (err) => {
if (err) { if (err) {
console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -986,7 +1003,10 @@ sendSystemControlCommand(command: AVControlCommand): Promise\<void> ...@@ -986,7 +1003,10 @@ sendSystemControlCommand(command: AVControlCommand): Promise\<void>
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let cmd : avSession.AVControlCommandType = 'play'; let cmd : avSession.AVControlCommandType = 'play';
// let cmd : avSession.AVControlCommandType = 'pause'; // let cmd : avSession.AVControlCommandType = 'pause';
// let cmd : avSession.AVControlCommandType = 'stop'; // let cmd : avSession.AVControlCommandType = 'stop';
...@@ -994,7 +1014,7 @@ let cmd : avSession.AVControlCommandType = 'play'; ...@@ -994,7 +1014,7 @@ let cmd : avSession.AVControlCommandType = 'play';
// let cmd : avSession.AVControlCommandType = 'playPrevious'; // let cmd : avSession.AVControlCommandType = 'playPrevious';
// let cmd : avSession.AVControlCommandType = 'fastForward'; // let cmd : avSession.AVControlCommandType = 'fastForward';
// let cmd : avSession.AVControlCommandType = 'rewind'; // let cmd : avSession.AVControlCommandType = 'rewind';
let avcommand = {command:cmd}; let avcommand: avSession.AVControlCommand = {command:cmd};
// let cmd : avSession.AVControlCommandType = 'seek'; // let cmd : avSession.AVControlCommandType = 'seek';
// let avcommand = {command:cmd, parameter:10}; // let avcommand = {command:cmd, parameter:10};
// let cmd : avSession.AVControlCommandType = 'setSpeed'; // let cmd : avSession.AVControlCommandType = 'setSpeed';
...@@ -1005,7 +1025,7 @@ let avcommand = {command:cmd}; ...@@ -1005,7 +1025,7 @@ let avcommand = {command:cmd};
// let avcommand = {command:cmd, parameter:"false"}; // let avcommand = {command:cmd, parameter:"false"};
avSession.sendSystemControlCommand(avcommand).then(() => { avSession.sendSystemControlCommand(avcommand).then(() => {
console.info(`SendSystemControlCommand successfully`); console.info(`SendSystemControlCommand successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1043,8 +1063,10 @@ startCastDeviceDiscovery(callback: AsyncCallback\<void>): void ...@@ -1043,8 +1063,10 @@ startCastDeviceDiscovery(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avSession.startCastDeviceDiscovery(function (err) { import { BusinessError } from '@ohos.base';
avSession.startCastDeviceDiscovery((err: BusinessError) => {
if (err) { if (err) {
console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1073,9 +1095,11 @@ startCastDeviceDiscovery(filter: number, callback: AsyncCallback\<void>): void ...@@ -1073,9 +1095,11 @@ startCastDeviceDiscovery(filter: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let filter = 2; let filter = 2;
avSession.startCastDeviceDiscovery(filter, function (err) { avSession.startCastDeviceDiscovery(filter, (err: BusinessError) => {
if (err) { if (err) {
console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1107,11 +1131,13 @@ startCastDeviceDiscovery(filter?: number): Promise\<void> ...@@ -1107,11 +1131,13 @@ startCastDeviceDiscovery(filter?: number): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let filter = 2; let filter = 2;
avSession.startCastDeviceDiscovery(filter).then(() => { avSession.startCastDeviceDiscovery(filter).then(() => {
console.info(`startCastDeviceDiscovery successfully`); console.info(`startCastDeviceDiscovery successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1135,8 +1161,10 @@ stopCastDeviceDiscovery(callback: AsyncCallback\<void>): void ...@@ -1135,8 +1161,10 @@ stopCastDeviceDiscovery(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avSession.stopCastDeviceDiscovery(function (err) { import { BusinessError } from '@ohos.base';
avSession.stopCastDeviceDiscovery((err: BusinessError) => {
if (err) { if (err) {
console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1163,10 +1191,12 @@ stopCastDeviceDiscovery(): Promise\<void> ...@@ -1163,10 +1191,12 @@ stopCastDeviceDiscovery(): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
avSession.stopCastDeviceDiscovery().then(() => { avSession.stopCastDeviceDiscovery().then(() => {
console.info(`startCastDeviceDiscovery successfully`); console.info(`startCastDeviceDiscovery successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1191,8 +1221,10 @@ setDiscoverable(enable: boolean, callback: AsyncCallback\<void>): void ...@@ -1191,8 +1221,10 @@ setDiscoverable(enable: boolean, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avSession.setDiscoverable(true, function (err) { import { BusinessError } from '@ohos.base';
avSession.setDiscoverable(true, (err: BusinessError) => {
if (err) { if (err) {
console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1225,10 +1257,12 @@ setDiscoverable(enable: boolean): Promise\<void> ...@@ -1225,10 +1257,12 @@ setDiscoverable(enable: boolean): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
avSession.setDiscoverable(true).then(() => { avSession.setDiscoverable(true).then(() => {
console.info(`setDiscoverable successfully`); console.info(`setDiscoverable successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1259,9 +1293,9 @@ on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void ...@@ -1259,9 +1293,9 @@ on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void
**示例:** **示例:**
```js ```ts
let castDevice; let castDevice: avSession.OutputDeviceInfo;
avSession.on('deviceAvailable', (device) => { avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => {
castDevice = device; castDevice = device;
console.info(`on deviceAvailable : ${device} `); console.info(`on deviceAvailable : ${device} `);
}); });
...@@ -1292,7 +1326,7 @@ off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): voi ...@@ -1292,7 +1326,7 @@ off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): voi
**示例:** **示例:**
```js ```ts
avSession.off('deviceAvailable'); avSession.off('deviceAvailable');
``` ```
...@@ -1325,15 +1359,15 @@ getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController ...@@ -1325,15 +1359,15 @@ getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let sessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1343,8 +1377,8 @@ avSession.createAVSession(context, tag, "audio", function (err, data) { ...@@ -1343,8 +1377,8 @@ avSession.createAVSession(context, tag, "audio", function (err, data) {
} }
}); });
let aVCastController; let aVCastController: avSession.AVCastController;
avSession.getAVCastController(sessionId ,function (err, avcontroller) { avSession.getAVCastController(sessionId , (err: BusinessError, avcontroller: avSession.AVCastController) => {
if (err) { if (err) {
console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1388,15 +1422,15 @@ getAVCastController(sessionId: string): Promise\<AVCastController>; ...@@ -1388,15 +1422,15 @@ getAVCastController(sessionId: string): Promise\<AVCastController>;
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let sessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1406,11 +1440,11 @@ avSession.createAVSession(context, tag, "audio", function (err, data) { ...@@ -1406,11 +1440,11 @@ avSession.createAVSession(context, tag, "audio", function (err, data) {
} }
}); });
let aVCastController; let aVCastController: avSession.AVCastController;
avSession.getAVCastController(sessionId).then((avcontroller) => { avSession.getAVCastController(sessionId).then((avcontroller: avSession.AVCastController) => {
aVCastController = avcontroller; aVCastController = avcontroller;
console.info('getAVCastController : SUCCESS'); console.info('getAVCastController : SUCCESS');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1445,33 +1479,34 @@ startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCal ...@@ -1445,33 +1479,34 @@ startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCal
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let currSessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
currentAVSession = data; currentAVSession = data;
currSessionId = currentAVSession.sessionId; sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
} }
}); });
let myToken = { let myToken: avSession.SessionToken = {
sessionId: currSessionId, sessionId: sessionId,
} }
let castDevice; let castDevice: avSession.OutputDeviceInfo;
avSession.on('deviceAvailable', (device) => { avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => {
castDevice = device; castDevice = device;
console.info(`on deviceAvailable : ${device} `); console.info(`on deviceAvailable : ${device} `);
}); });
avSession.startCasting(myToken, castDevice, function (err) { avSession.startCasting(myToken, castDevice, (err: BusinessError) => {
if (err) { if (err) {
console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1515,35 +1550,36 @@ startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void> ...@@ -1515,35 +1550,36 @@ startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void>
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let currSessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
currentAVSession = data; currentAVSession = data;
currSessionId = currentAVSession.sessionId; sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
} }
}); });
let myToken = { let myToken: avSession.SessionToken = {
sessionId: currSessionId, sessionId: sessionId,
} }
let castDevice; let castDevice: avSession.OutputDeviceInfo;
avSession.on('deviceAvailable', (device) => { avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => {
castDevice = device; castDevice = device;
console.info(`on deviceAvailable : ${device} `); console.info(`on deviceAvailable : ${device} `);
}); });
avSession.startCasting(myToken, castDevice).then(() => { avSession.startCasting(myToken, castDevice).then(() => {
console.info(`startCasting successfully`); console.info(`startCasting successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1574,28 +1610,29 @@ stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void ...@@ -1574,28 +1610,29 @@ stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let currSessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
currentAVSession = data; currentAVSession = data;
currSessionId = currentAVSession.sessionId; sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
} }
}); });
let myToken = { let myToken: avSession.SessionToken = {
sessionId: currSessionId, sessionId: sessionId,
} }
avSession.stopCasting(myToken, function (err) { avSession.stopCasting(myToken, (err: BusinessError) => {
if (err) { if (err) {
console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1635,32 +1672,34 @@ stopCasting(session: SessionToken): Promise\<void> ...@@ -1635,32 +1672,34 @@ stopCasting(session: SessionToken): Promise\<void>
**示例:** **示例:**
```js ```ts
import featureAbility from '@ohos.ability.featureAbility'; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let currentAVSession; let currentAVSession: avSession.AVSession;
let tag = "createNewSession"; let tag = "createNewSession";
let context = featureAbility.getContext(); let context: Context = this.context;
let currSessionId; //供后续函数入参使用 let sessionId: string; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
currentAVSession = data; currentAVSession = data;
currSessionId = currentAVSession.sessionId; sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`); console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
} }
}); });
let myToken = { let myToken: avSession.SessionToken = {
sessionId: currSessionId, sessionId: sessionId,
} }
avSession.stopCasting(myToken).then(() => { avSession.stopCasting(myToken).then(() => {
console.info(`stopCasting successfully`); console.info(`stopCasting successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
## AVSessionType<sup>10+<sup> ## AVSessionType<sup>10+<sup>
...@@ -1688,9 +1727,9 @@ avSession.stopCasting(myToken).then(() => { ...@@ -1688,9 +1727,9 @@ avSession.stopCasting(myToken).then(() => {
**示例:** **示例:**
```js ```ts
let sessionId = currentAVSession.sessionId; let sessionId: string = currentAVSession.sessionId;
let sessionType = currentAVSession.sessionType; let sessionType: avSession.AVSessionType = currentAVSession.sessionType;
``` ```
### setAVMetadata<sup>10+</sup> ### setAVMetadata<sup>10+</sup>
...@@ -1723,8 +1762,11 @@ setAVMetadata(data: AVMetadata): Promise\<void> ...@@ -1723,8 +1762,11 @@ setAVMetadata(data: AVMetadata): Promise\<void>
**示例:** **示例:**
```js ```ts
let metadata = { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let metadata: avSession.AVMetadata = {
assetId: "121278", assetId: "121278",
title: "lose yourself", title: "lose yourself",
artist: "Eminem", artist: "Eminem",
...@@ -1742,7 +1784,7 @@ let metadata = { ...@@ -1742,7 +1784,7 @@ let metadata = {
}; };
currentAVSession.setAVMetadata(metadata).then(() => { currentAVSession.setAVMetadata(metadata).then(() => {
console.info(`SetAVMetadata successfully`); console.info(`SetAVMetadata successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1772,8 +1814,11 @@ setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void ...@@ -1772,8 +1814,11 @@ setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let metadata = { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let metadata: avSession.AVMetadata = {
assetId: "121278", assetId: "121278",
title: "lose yourself", title: "lose yourself",
artist: "Eminem", artist: "Eminem",
...@@ -1789,7 +1834,7 @@ let metadata = { ...@@ -1789,7 +1834,7 @@ let metadata = {
previousAssetId: "121277", previousAssetId: "121277",
nextAssetId: "121279", nextAssetId: "121279",
}; };
currentAVSession.setAVMetadata(metadata, function (err) { currentAVSession.setAVMetadata(metadata, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1828,8 +1873,11 @@ setAVPlaybackState(state: AVPlaybackState): Promise\<void> ...@@ -1828,8 +1873,11 @@ setAVPlaybackState(state: AVPlaybackState): Promise\<void>
**示例:** **示例:**
```js ```ts
let playbackState = { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let playbackState: avSession.AVPlaybackState = {
state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
speed: 1.0, speed: 1.0,
position:{elapsedTime:10, updateTime:(new Date()).getTime()}, position:{elapsedTime:10, updateTime:(new Date()).getTime()},
...@@ -1839,7 +1887,7 @@ let playbackState = { ...@@ -1839,7 +1887,7 @@ let playbackState = {
}; };
currentAVSession.setAVPlaybackState(playbackState).then(() => { currentAVSession.setAVPlaybackState(playbackState).then(() => {
console.info(`SetAVPlaybackState successfully`); console.info(`SetAVPlaybackState successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1869,8 +1917,11 @@ setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void ...@@ -1869,8 +1917,11 @@ setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let PlaybackState = { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let PlaybackState: avSession.AVPlaybackState = {
state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
speed: 1.0, speed: 1.0,
position:{elapsedTime:10, updateTime:(new Date()).getTime()}, position:{elapsedTime:10, updateTime:(new Date()).getTime()},
...@@ -1878,7 +1929,7 @@ let PlaybackState = { ...@@ -1878,7 +1929,7 @@ let PlaybackState = {
loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
isFavorite:true, isFavorite:true,
}; };
currentAVSession.setAVPlaybackState(PlaybackState, function (err) { currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => {
if (err) { if (err) {
console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -1917,11 +1968,12 @@ setLaunchAbility(ability: WantAgent): Promise\<void> ...@@ -1917,11 +1968,12 @@ setLaunchAbility(ability: WantAgent): Promise\<void>
**示例:** **示例:**
```js ```ts
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
import { BusinessError } from '@ohos.base';
//WantAgentInfo对象 //WantAgentInfo对象
let wantAgentInfo = { let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
deviceId: "deviceId", deviceId: "deviceId",
...@@ -1951,7 +2003,7 @@ let wantAgentInfo = { ...@@ -1951,7 +2003,7 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((agent) => { wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
currentAVSession.setLaunchAbility(agent).then(() => { currentAVSession.setLaunchAbility(agent).then(() => {
console.info(`SetLaunchAbility successfully`); console.info(`SetLaunchAbility successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
}); });
...@@ -1982,11 +2034,12 @@ setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void ...@@ -1982,11 +2034,12 @@ setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
import { BusinessError } from '@ohos.base';
//WantAgentInfo对象 //WantAgentInfo对象
let wantAgentInfo = { let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
deviceId: "deviceId", deviceId: "deviceId",
...@@ -2014,7 +2067,7 @@ let wantAgentInfo = { ...@@ -2014,7 +2067,7 @@ let wantAgentInfo = {
} }
wantAgent.getWantAgent(wantAgentInfo).then((agent) => { wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
currentAVSession.setLaunchAbility(agent, function (err) { currentAVSession.setLaunchAbility(agent, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2058,12 +2111,26 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<voi ...@@ -2058,12 +2111,26 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<voi
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
let eventName = "dynamic_lyric"; let eventName = "dynamic_lyric";
let args = {
lyric : "This is lyric" currentAVSession.dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => {
} console.info(`dispatchSessionEvent successfully`);
currentAVSession.dispatchSessionEvent(eventName, args).catch((err) => { }).catch((err: BusinessError) => {
console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -2097,12 +2164,23 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: Asy ...@@ -2097,12 +2164,23 @@ dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: Asy
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
let eventName = "dynamic_lyric"; let eventName = "dynamic_lyric";
let args = { currentAVSession.dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => {
lyric : "This is lyric"
}
currentAVSession.dispatchSessionEvent(eventName, args, (err) => {
if(err) { if(err) {
console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
} }
...@@ -2139,43 +2217,48 @@ setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void> ...@@ -2139,43 +2217,48 @@ setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void>
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
import avSession from '@ohos.multimedia.avsession';
let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); let value: Uint8Array = resourceManager.getRawFileContent('IMAGE_URI');
let imageSource : imageImageSource = image.createImageSource(value.buffer); let imageSource: image.ImageSource = image.createImageSource(value.buffer);
let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); let imagePixel: image.PixelMap;
let queueItemDescription_1 = { imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}).then((data) => {
mediaId: '001', imagePixel = data;
}).catch((err: BusinessError) => {
console.error(`createPixelMap BusinessError: code: ${err.code}, message: ${err.message}`);
})
let queueItemDescription_1: avSession.AVMediaDescription = {
assetId: '001',
title: 'music_name', title: 'music_name',
subtitle: 'music_sub_name', subtitle: 'music_sub_name',
description: 'music_description', description: 'music_description',
icon : imagePixel, mediaImage : imagePixel,
iconUri: 'http://www.icon.uri.com', extras: {extras:'any'}
extras: {'extras':'any'}
}; };
let queueItem_1 = { let queueItem_1: avSession.AVQueueItem = {
itemId: 1, itemId: 1,
description: queueItemDescription_1 description: queueItemDescription_1
}; };
let queueItemDescription_2 = { let queueItemDescription_2: avSession.AVMediaDescription = {
mediaId: '002', assetId: '002',
title: 'music_name', title: 'music_name',
subtitle: 'music_sub_name', subtitle: 'music_sub_name',
description: 'music_description', description: 'music_description',
icon: imagePixel, mediaImage: imagePixel,
iconUri: 'http://www.xxx.com', extras: {extras:'any'}
extras: {'extras':'any'}
}; };
let queueItem_2 = { let queueItem_2: avSession.AVQueueItem = {
itemId: 2, itemId: 2,
description: queueItemDescription_2 description: queueItemDescription_2
}; };
let queueItemsArray = [queueItem_1, queueItem_2]; let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
currentAVSession.setAVQueueItems(queueItemsArray).then(() => { currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
console.info(`SetAVQueueItems successfully`); console.info(`SetAVQueueItems successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2205,41 +2288,46 @@ setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): voi ...@@ -2205,41 +2288,46 @@ setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): voi
**示例:** **示例:**
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { BusinessError } from '@ohos.base';
import avSession from '@ohos.multimedia.avsession';
let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); let value: Uint8Array = resourceManager.getRawFileContent('IMAGE_URI');
let imageSource : imageImageSource = image.createImageSource(value.buffer); let imageSource: image.ImageSource = image.createImageSource(value.buffer);
let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); let imagePixel: image.PixelMap;
let queueItemDescription_1 = { imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}).then((data) => {
mediaId: '001', imagePixel = data;
}).catch((err: BusinessError) => {
console.error(`createPixelMap BusinessError: code: ${err.code}, message: ${err.message}`);
})
let queueItemDescription_1: avSession.AVMediaDescription = {
assetId: '001',
title: 'music_name', title: 'music_name',
subtitle: 'music_sub_name', subtitle: 'music_sub_name',
description: 'music_description', description: 'music_description',
icon: imagePixel, mediaImage : imagePixel,
iconUri: 'http://www.icon.uri.com', extras: {extras:'any'}
extras: {'extras':'any'}
}; };
let queueItem_1 = { let queueItem_1: avSession.AVQueueItem = {
itemId: 1, itemId: 1,
description: queueItemDescription_1 description: queueItemDescription_1
}; };
let queueItemDescription_2 = { let queueItemDescription_2: avSession.AVMediaDescription = {
mediaId: '002', assetId: '002',
title: 'music_name', title: 'music_name',
subtitle: 'music_sub_name', subtitle: 'music_sub_name',
description: 'music_description', description: 'music_description',
icon: imagePixel, mediaImage: imagePixel,
iconUri: 'http://www.icon.uri.com', extras: {extras:'any'}
extras: {'extras':'any'}
}; };
let queueItem_2 = { let queueItem_2: avSession.AVQueueItem = {
itemId: 2, itemId: 2,
description: queueItemDescription_2 description: queueItemDescription_2
}; };
let queueItemsArray = [queueItem_1, queueItem_2]; let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
currentAVSession.setAVQueueItems(queueItemsArray, function (err) { currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2278,11 +2366,13 @@ setAVQueueTitle(title: string): Promise\<void> ...@@ -2278,11 +2366,13 @@ setAVQueueTitle(title: string): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let queueTitle = 'QUEUE_TITLE'; let queueTitle = 'QUEUE_TITLE';
currentAVSession.setAVQueueTitle(queueTitle).then(() => { currentAVSession.setAVQueueTitle(queueTitle).then(() => {
console.info(`SetAVQueueTitle successfully`); console.info(`SetAVQueueTitle successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2312,9 +2402,11 @@ setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void ...@@ -2312,9 +2402,11 @@ setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let queueTitle = 'QUEUE_TITLE'; let queueTitle = 'QUEUE_TITLE';
currentAVSession.setAVQueueTitle(queueTitle, function (err) { currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => {
if (err) { if (err) {
console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2356,11 +2448,22 @@ setExtras(extras: {[key: string]: Object}): Promise\<void> ...@@ -2356,11 +2448,22 @@ setExtras(extras: {[key: string]: Object}): Promise\<void>
**示例:** **示例:**
```js ```ts
let extras = { import avSession from '@ohos.multimedia.avsession';
extras : "This is custom media packet" import { BusinessError } from '@ohos.base';
}
currentAVSession.setExtras(extras).catch((err) => { let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
currentAVSession.setExtras({"extras" : "This is custom media packet"}).catch((err: BusinessError) => {
console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -2393,11 +2496,22 @@ setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void ...@@ -2393,11 +2496,22 @@ setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let extras = { import avSession from '@ohos.multimedia.avsession';
extras : "This is custom media packet" import { BusinessError } from '@ohos.base';
}
currentAVSession.setExtras(extras, (err) => { let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
currentAVSession.setExtras({"extras" : "This is custom media packet"}, (err: BusinessError) => {
if(err) { if(err) {
console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
} }
...@@ -2428,12 +2542,14 @@ getController(): Promise\<AVSessionController> ...@@ -2428,12 +2542,14 @@ getController(): Promise\<AVSessionController>
**示例:** **示例:**
```js ```ts
let avsessionController; import { BusinessError } from '@ohos.base';
currentAVSession.getController().then((avcontroller) => {
let avsessionController: avSession.AVSessionController;
currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => {
avsessionController = avcontroller; avsessionController = avcontroller;
console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2462,9 +2578,11 @@ getController(callback: AsyncCallback\<AVSessionController>): void ...@@ -2462,9 +2578,11 @@ getController(callback: AsyncCallback\<AVSessionController>): void
**示例:** **示例:**
```js ```ts
let avsessionController; import { BusinessError } from '@ohos.base';
currentAVSession.getController(function (err, avcontroller) {
let avsessionController: avSession.AVSessionController;
currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => {
if (err) { if (err) {
console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2498,12 +2616,14 @@ getAVCastController(callback: AsyncCallback\<AVCastController>): void ...@@ -2498,12 +2616,14 @@ getAVCastController(callback: AsyncCallback\<AVCastController>): void
**示例:** **示例:**
```js ```ts
let aVCastController; import { BusinessError } from '@ohos.base';
currentAVSession.getAVCastController().then((avcontroller) => {
let aVCastController: avSession.AVCastController;
currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => {
aVCastController = avcontroller; aVCastController = avcontroller;
console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`); console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2532,9 +2652,11 @@ getAVCastController(): Promise\<AVCastController>; ...@@ -2532,9 +2652,11 @@ getAVCastController(): Promise\<AVCastController>;
**示例:** **示例:**
```js ```ts
let aVCastController; import { BusinessError } from '@ohos.base';
currentAVSession.getAVCastController(function (err, avcontroller) {
let aVCastController: avSession.AVCastController;
currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => {
if (err) { if (err) {
console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2569,12 +2691,14 @@ getOutputDevice(): Promise\<OutputDeviceInfo> ...@@ -2569,12 +2691,14 @@ getOutputDevice(): Promise\<OutputDeviceInfo>
**示例:** **示例:**
```js ```ts
currentAVSession.getOutputDevice().then((outputDeviceInfo) => { import { BusinessError } from '@ohos.base';
currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => {
console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
}); })
``` ```
### getOutputDevice<sup>10+</sup> ### getOutputDevice<sup>10+</sup>
...@@ -2602,8 +2726,10 @@ getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void ...@@ -2602,8 +2726,10 @@ getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
**示例:** **示例:**
```js ```ts
currentAVSession.getOutputDevice(function (err, outputDeviceInfo) { import { BusinessError } from '@ohos.base';
currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => {
if (err) { if (err) {
console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2636,10 +2762,12 @@ activate(): Promise\<void> ...@@ -2636,10 +2762,12 @@ activate(): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
currentAVSession.activate().then(() => { currentAVSession.activate().then(() => {
console.info(`Activate : SUCCESS `); console.info(`Activate : SUCCESS `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2668,8 +2796,10 @@ activate(callback: AsyncCallback\<void>): void ...@@ -2668,8 +2796,10 @@ activate(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
currentAVSession.activate(function (err) { import { BusinessError } from '@ohos.base';
currentAVSession.activate((err: BusinessError) => {
if (err) { if (err) {
console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2702,10 +2832,12 @@ deactivate(): Promise\<void> ...@@ -2702,10 +2832,12 @@ deactivate(): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
currentAVSession.deactivate().then(() => { currentAVSession.deactivate().then(() => {
console.info(`Deactivate : SUCCESS `); console.info(`Deactivate : SUCCESS `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2736,8 +2868,10 @@ deactivate(callback: AsyncCallback\<void>): void ...@@ -2736,8 +2868,10 @@ deactivate(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
currentAVSession.deactivate(function (err) { import { BusinessError } from '@ohos.base';
currentAVSession.deactivate((err: BusinessError) => {
if (err) { if (err) {
console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2770,10 +2904,12 @@ destroy(): Promise\<void> ...@@ -2770,10 +2904,12 @@ destroy(): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
currentAVSession.destroy().then(() => { currentAVSession.destroy().then(() => {
console.info(`Destroy : SUCCESS `); console.info(`Destroy : SUCCESS `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2802,8 +2938,10 @@ destroy(callback: AsyncCallback\<void>): void ...@@ -2802,8 +2938,10 @@ destroy(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
currentAVSession.destroy(function (err) { import { BusinessError } from '@ohos.base';
currentAVSession.destroy((err: BusinessError) => {
if (err) { if (err) {
console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -2837,7 +2975,7 @@ on(type: 'play', callback: () => void): void ...@@ -2837,7 +2975,7 @@ on(type: 'play', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('play', () => { currentAVSession.on('play', () => {
console.info(`on play entry`); console.info(`on play entry`);
}); });
...@@ -2868,7 +3006,7 @@ on(type: 'pause', callback: () => void): void ...@@ -2868,7 +3006,7 @@ on(type: 'pause', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('pause', () => { currentAVSession.on('pause', () => {
console.info(`on pause entry`); console.info(`on pause entry`);
}); });
...@@ -2899,7 +3037,7 @@ on(type:'stop', callback: () => void): void ...@@ -2899,7 +3037,7 @@ on(type:'stop', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('stop', () => { currentAVSession.on('stop', () => {
console.info(`on stop entry`); console.info(`on stop entry`);
}); });
...@@ -2930,7 +3068,7 @@ on(type:'playNext', callback: () => void): void ...@@ -2930,7 +3068,7 @@ on(type:'playNext', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('playNext', () => { currentAVSession.on('playNext', () => {
console.info(`on playNext entry`); console.info(`on playNext entry`);
}); });
...@@ -2961,7 +3099,7 @@ on(type:'playPrevious', callback: () => void): void ...@@ -2961,7 +3099,7 @@ on(type:'playPrevious', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('playPrevious', () => { currentAVSession.on('playPrevious', () => {
console.info(`on playPrevious entry`); console.info(`on playPrevious entry`);
}); });
...@@ -2992,7 +3130,7 @@ on(type: 'fastForward', callback: () => void): void ...@@ -2992,7 +3130,7 @@ on(type: 'fastForward', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('fastForward', () => { currentAVSession.on('fastForward', () => {
console.info(`on fastForward entry`); console.info(`on fastForward entry`);
}); });
...@@ -3023,7 +3161,7 @@ on(type:'rewind', callback: () => void): void ...@@ -3023,7 +3161,7 @@ on(type:'rewind', callback: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('rewind', () => { currentAVSession.on('rewind', () => {
console.info(`on rewind entry`); console.info(`on rewind entry`);
}); });
...@@ -3054,8 +3192,8 @@ on(type: 'seek', callback: (time: number) => void): void ...@@ -3054,8 +3192,8 @@ on(type: 'seek', callback: (time: number) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('seek', (time) => { currentAVSession.on('seek', (time: number) => {
console.info(`on seek entry time : ${time}`); console.info(`on seek entry time : ${time}`);
}); });
``` ```
...@@ -3085,8 +3223,8 @@ on(type: 'setSpeed', callback: (speed: number) => void): void ...@@ -3085,8 +3223,8 @@ on(type: 'setSpeed', callback: (speed: number) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('setSpeed', (speed) => { currentAVSession.on('setSpeed', (speed: number) => {
console.info(`on setSpeed speed : ${speed}`); console.info(`on setSpeed speed : ${speed}`);
}); });
``` ```
...@@ -3116,8 +3254,8 @@ on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void ...@@ -3116,8 +3254,8 @@ on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('setLoopMode', (mode) => { currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => {
console.info(`on setLoopMode mode : ${mode}`); console.info(`on setLoopMode mode : ${mode}`);
}); });
``` ```
...@@ -3147,8 +3285,8 @@ on(type: 'toggleFavorite', callback: (assetId: string) => void): void ...@@ -3147,8 +3285,8 @@ on(type: 'toggleFavorite', callback: (assetId: string) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('toggleFavorite', (assetId) => { currentAVSession.on('toggleFavorite', (assetId: string) => {
console.info(`on toggleFavorite mode : ${assetId}`); console.info(`on toggleFavorite mode : ${assetId}`);
}); });
``` ```
...@@ -3178,8 +3316,8 @@ on(type: 'skipToQueueItem', callback: (itemId: number) => void): void ...@@ -3178,8 +3316,8 @@ on(type: 'skipToQueueItem', callback: (itemId: number) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('skipToQueueItem', (itemId) => { currentAVSession.on('skipToQueueItem', (itemId: number) => {
console.info(`on skipToQueueItem id : ${itemId}`); console.info(`on skipToQueueItem id : ${itemId}`);
}); });
``` ```
...@@ -3209,10 +3347,13 @@ on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void ...@@ -3209,10 +3347,13 @@ on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.on('handleKeyEvent', (event) => { import keyEvent from '@ohos.multimodalInput.keyEvent';
currentAVSession.on('handleKeyEvent', (event: keyEvent.KeyEvent) => {
console.info(`on handleKeyEvent event : ${event}`); console.info(`on handleKeyEvent event : ${event}`);
}); });
``` ```
### on('outputDeviceChange')<sup>10+</sup> ### on('outputDeviceChange')<sup>10+</sup>
...@@ -3240,8 +3381,8 @@ on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: Output ...@@ -3240,8 +3381,8 @@ on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: Output
**示例:** **示例:**
```js ```ts
currentAVSession.on('outputDeviceChange', (state, device) => { currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
console.info(`on outputDeviceChange device : ${device}`); console.info(`on outputDeviceChange device : ${device}`);
}); });
``` ```
...@@ -3271,7 +3412,20 @@ on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Obje ...@@ -3271,7 +3412,20 @@ on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Obje
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
import avSession from '@ohos.multimedia.avsession';
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
currentAVSession.on('commonCommand', (commonCommand, args) => { currentAVSession.on('commonCommand', (commonCommand, args) => {
console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
}); });
...@@ -3302,7 +3456,7 @@ off(type: 'play', callback?: () => void): void ...@@ -3302,7 +3456,7 @@ off(type: 'play', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('play'); currentAVSession.off('play');
``` ```
...@@ -3331,7 +3485,7 @@ off(type: 'pause', callback?: () => void): void ...@@ -3331,7 +3485,7 @@ off(type: 'pause', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('pause'); currentAVSession.off('pause');
``` ```
...@@ -3360,7 +3514,7 @@ off(type: 'stop', callback?: () => void): void ...@@ -3360,7 +3514,7 @@ off(type: 'stop', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('stop'); currentAVSession.off('stop');
``` ```
...@@ -3389,7 +3543,7 @@ off(type: 'playNext', callback?: () => void): void ...@@ -3389,7 +3543,7 @@ off(type: 'playNext', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('playNext'); currentAVSession.off('playNext');
``` ```
...@@ -3418,7 +3572,7 @@ off(type: 'playPrevious', callback?: () => void): void ...@@ -3418,7 +3572,7 @@ off(type: 'playPrevious', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('playPrevious'); currentAVSession.off('playPrevious');
``` ```
...@@ -3447,7 +3601,7 @@ off(type: 'fastForward', callback?: () => void): void ...@@ -3447,7 +3601,7 @@ off(type: 'fastForward', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('fastForward'); currentAVSession.off('fastForward');
``` ```
...@@ -3476,7 +3630,7 @@ off(type: 'rewind', callback?: () => void): void ...@@ -3476,7 +3630,7 @@ off(type: 'rewind', callback?: () => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('rewind'); currentAVSession.off('rewind');
``` ```
...@@ -3505,7 +3659,7 @@ off(type: 'seek', callback?: (time: number) => void): void ...@@ -3505,7 +3659,7 @@ off(type: 'seek', callback?: (time: number) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('seek'); currentAVSession.off('seek');
``` ```
...@@ -3534,7 +3688,7 @@ off(type: 'setSpeed', callback?: (speed: number) => void): void ...@@ -3534,7 +3688,7 @@ off(type: 'setSpeed', callback?: (speed: number) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('setSpeed'); currentAVSession.off('setSpeed');
``` ```
...@@ -3563,7 +3717,7 @@ off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void ...@@ -3563,7 +3717,7 @@ off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('setLoopMode'); currentAVSession.off('setLoopMode');
``` ```
...@@ -3592,7 +3746,7 @@ off(type: 'toggleFavorite', callback?: (assetId: string) => void): void ...@@ -3592,7 +3746,7 @@ off(type: 'toggleFavorite', callback?: (assetId: string) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('toggleFavorite'); currentAVSession.off('toggleFavorite');
``` ```
...@@ -3621,7 +3775,7 @@ off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void ...@@ -3621,7 +3775,7 @@ off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('skipToQueueItem'); currentAVSession.off('skipToQueueItem');
``` ```
...@@ -3650,7 +3804,7 @@ off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void ...@@ -3650,7 +3804,7 @@ off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
**示例:** **示例:**
```js ```ts
currentAVSession.off('handleKeyEvent'); currentAVSession.off('handleKeyEvent');
``` ```
...@@ -3679,7 +3833,7 @@ off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: Outp ...@@ -3679,7 +3833,7 @@ off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: Outp
**示例:** **示例:**
```js ```ts
currentAVSession.off('outputDeviceChange'); currentAVSession.off('outputDeviceChange');
``` ```
...@@ -3709,7 +3863,7 @@ off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Obj ...@@ -3709,7 +3863,7 @@ off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Obj
**示例:** **示例:**
```js ```ts
currentAVSession.off('commonCommand'); currentAVSession.off('commonCommand');
``` ```
...@@ -3736,8 +3890,10 @@ stopCasting(callback: AsyncCallback\<void>): void ...@@ -3736,8 +3890,10 @@ stopCasting(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
currentAVSession.stopCasting(function (err) { import { BusinessError } from '@ohos.base';
currentAVSession.stopCasting((err: BusinessError) => {
if (err) { if (err) {
console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -3769,10 +3925,12 @@ stopCasting(): Promise\<void> ...@@ -3769,10 +3925,12 @@ stopCasting(): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
currentAVSession.stopCasting().then(() => { currentAVSession.stopCasting().then(() => {
console.info(`stopCasting successfully`); console.info(`stopCasting successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -3837,9 +3995,9 @@ setDisplaySurface(surfaceId: string): Promise\<void> ...@@ -3837,9 +3995,9 @@ setDisplaySurface(surfaceId: string): Promise\<void>
| 6600109 | The remote connection is not established. | | 6600109 | The remote connection is not established. |
**示例:** **示例:**
```js ```ts
aVCastController.setDisplaySurface().then(() => { aVCastController.setDisplaySurface().then(() => {
console.info(`setDisplaySurface : SUCCESS :`); console.info(`setDisplaySurface : SUCCESS`);
}); });
``` ```
...@@ -3867,12 +4025,14 @@ setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void ...@@ -3867,12 +4025,14 @@ setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
| 6600109 | The remote connection is not established. | | 6600109 | The remote connection is not established. |
**示例:** **示例:**
```js ```ts
aVCastController.setDisplaySurface(function (err, value) { import { BusinessError } from '@ohos.base';
aVCastController.setDisplaySurface((err: BusinessError) => {
if (err) { if (err) {
console.info(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info(`setDisplaySurface : SUCCESS : state : ${value}`); console.info(`setDisplaySurface : SUCCESS`);
} }
}); });
``` ```
...@@ -3900,8 +4060,10 @@ getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void ...@@ -3900,8 +4060,10 @@ getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
**示例:** **示例:**
```js ```ts
aVCastController.getAVPlaybackState(function (err, state) { import { BusinessError } from '@ohos.base';
aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
if (err) { if (err) {
console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -3933,10 +4095,12 @@ getAVPlaybackState(): Promise\<AVPlaybackState>; ...@@ -3933,10 +4095,12 @@ getAVPlaybackState(): Promise\<AVPlaybackState>;
**示例:** **示例:**
```js ```ts
aVCastController.getAVPlaybackState().then((state) => { import { BusinessError } from '@ohos.base';
console.info(`getAVPlaybackState : SUCCESS :`);
}).catch((err) => { aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
console.info(`getAVPlaybackState : SUCCESS`);
}).catch((err: BusinessError) => {
console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -3973,8 +4137,11 @@ sendControlCommand(command: AVCastControlCommand): Promise\<void> ...@@ -3973,8 +4137,11 @@ sendControlCommand(command: AVCastControlCommand): Promise\<void>
**示例:** **示例:**
```js ```ts
let avCommand = {command:'play'}; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avCommand: avSession.AVCastControlCommand = {command:'play'};
// let avCommand = {command:'pause'}; // let avCommand = {command:'pause'};
// let avCommand = {command:'stop'}; // let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'}; // let avCommand = {command:'playNext'};
...@@ -3984,7 +4151,7 @@ let avCommand = {command:'play'}; ...@@ -3984,7 +4151,7 @@ let avCommand = {command:'play'};
// let avCommand = {command:'seek', parameter:10}; // let avCommand = {command:'seek', parameter:10};
aVCastController.sendControlCommand(avCommand).then(() => { aVCastController.sendControlCommand(avCommand).then(() => {
console.info(`SendControlCommand successfully`); console.info(`SendControlCommand successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -4016,8 +4183,11 @@ sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void> ...@@ -4016,8 +4183,11 @@ sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>
**示例:** **示例:**
```js ```ts
let avCommand = {command:'play'}; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avCommand: avSession.AVCastControlCommand = {command:'play'};
// let avCommand = {command:'pause'}; // let avCommand = {command:'pause'};
// let avCommand = {command:'stop'}; // let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'}; // let avCommand = {command:'playNext'};
...@@ -4025,7 +4195,7 @@ let avCommand = {command:'play'}; ...@@ -4025,7 +4195,7 @@ let avCommand = {command:'play'};
// let avCommand = {command:'fastForward'}; // let avCommand = {command:'fastForward'};
// let avCommand = {command:'rewind'}; // let avCommand = {command:'rewind'};
// let avCommand = {command:'seek', parameter:10}; // let avCommand = {command:'seek', parameter:10};
aVCastController.sendControlCommand(avCommand, function (err) { aVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -4047,7 +4217,7 @@ prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void ...@@ -4047,7 +4217,7 @@ prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------- | ---- | ------------------------------ | | ------- | ------------------------------------- | ---- | ------------------------------ |
| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | | item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。
...@@ -4058,13 +4228,15 @@ prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void ...@@ -4058,13 +4228,15 @@ prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
// 设置播放参数,开始播放 // 设置播放参数,开始播放
var playItem = { let playItem: avSession.AVQueueItem = {
itemId: 0, itemId: 0,
description: { description: {
mediaId: '12345', assetId: '12345',
mediaName: 'song1',
mediaType: 'AUDIO', mediaType: 'AUDIO',
mediaUri: 'http://resource1_address', mediaUri: 'http://resource1_address',
mediaSize: 12345, mediaSize: 12345,
...@@ -4074,13 +4246,16 @@ var playItem = { ...@@ -4074,13 +4246,16 @@ var playItem = {
albumTitle: 'song1_title', albumTitle: 'song1_title',
albumCoverUri: "http://resource1_album_address", albumCoverUri: "http://resource1_album_address",
lyricUri: "http://resource1_lyric_address", lyricUri: "http://resource1_lyric_address",
iconUri: "http://resource1_icon_address",
appName: 'MyMusic' appName: 'MyMusic'
} }
}; };
// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 // 准备播放,这个不会触发真正的播放,会进行加载和缓冲
aVCastController.prepare(playItem, () => { aVCastController.prepare(playItem, (err: BusinessError) => {
console.info('prepare done'); if (err) {
console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
console.info(`prepare successfully`);
}
}); });
``` ```
...@@ -4116,13 +4291,15 @@ prepare(item: AVQueueItem): Promise\<void> ...@@ -4116,13 +4291,15 @@ prepare(item: AVQueueItem): Promise\<void>
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
// 设置播放参数,开始播放 // 设置播放参数,开始播放
var playItem = { let playItem: avSession.AVQueueItem = {
itemId: 0, itemId: 0,
description: { description: {
mediaId: '12345', assetId: '12345',
mediaName: 'song1',
mediaType: 'AUDIO', mediaType: 'AUDIO',
mediaUri: 'http://resource1_address', mediaUri: 'http://resource1_address',
mediaSize: 12345, mediaSize: 12345,
...@@ -4132,13 +4309,14 @@ var playItem = { ...@@ -4132,13 +4309,14 @@ var playItem = {
albumTitle: 'song1_title', albumTitle: 'song1_title',
albumCoverUri: "http://resource1_album_address", albumCoverUri: "http://resource1_album_address",
lyricUri: "http://resource1_lyric_address", lyricUri: "http://resource1_lyric_address",
iconUri: "http://resource1_icon_address",
appName: 'MyMusic' appName: 'MyMusic'
} }
}; };
// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 // 准备播放,这个不会触发真正的播放,会进行加载和缓冲
aVCastController.prepare(playItem, () => { aVCastController.prepare(playItem).then(() => {
console.info('prepare done'); console.info(`prepare successfully`);
}).catch((err: BusinessError) => {
console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -4155,7 +4333,7 @@ start(item: AVQueueItem, callback: AsyncCallback\<void>): void ...@@ -4155,7 +4333,7 @@ start(item: AVQueueItem, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------- | ---- | ------------------------------ | | ------- | ------------------------------------- | ---- | ------------------------------ |
| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | | item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。
...@@ -4166,13 +4344,15 @@ start(item: AVQueueItem, callback: AsyncCallback\<void>): void ...@@ -4166,13 +4344,15 @@ start(item: AVQueueItem, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
// 设置播放参数,开始播放 // 设置播放参数,开始播放
var playItem = { let playItem: avSession.AVQueueItem = {
itemId: 0, itemId: 0,
description: { description: {
mediaId: '12345', assetId: '12345',
mediaName: 'song1',
mediaType: 'AUDIO', mediaType: 'AUDIO',
mediaUri: 'http://resource1_address', mediaUri: 'http://resource1_address',
mediaSize: 12345, mediaSize: 12345,
...@@ -4182,14 +4362,17 @@ description: { ...@@ -4182,14 +4362,17 @@ description: {
albumTitle: 'song1_title', albumTitle: 'song1_title',
albumCoverUri: "http://resource1_album_address", albumCoverUri: "http://resource1_album_address",
lyricUri: "http://resource1_lyric_address", lyricUri: "http://resource1_lyric_address",
iconUri: "http://resource1_icon_address",
appName: 'MyMusic' appName: 'MyMusic'
} }
}; };
// 启动播放 // 启动播放
aVCastController.start(playItem, () => { aVCastController.start(playItem, (err: BusinessError) => {
console.info('play done'); if (err) {
console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
console.info(`start successfully`);
}
}); });
``` ```
...@@ -4224,13 +4407,15 @@ start(item: AVQueueItem): Promise\<void> ...@@ -4224,13 +4407,15 @@ start(item: AVQueueItem): Promise\<void>
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
// 设置播放参数,开始播放 // 设置播放参数,开始播放
var playItem = { let playItem: avSession.AVQueueItem = {
itemId: 0, itemId: 0,
description: { description: {
mediaId: '12345', assetId: '12345',
mediaName: 'song1',
mediaType: 'AUDIO', mediaType: 'AUDIO',
mediaUri: 'http://resource1_address', mediaUri: 'http://resource1_address',
mediaSize: 12345, mediaSize: 12345,
...@@ -4240,14 +4425,13 @@ description: { ...@@ -4240,14 +4425,13 @@ description: {
albumTitle: 'song1_title', albumTitle: 'song1_title',
albumCoverUri: "http://resource1_album_address", albumCoverUri: "http://resource1_album_address",
lyricUri: "http://resource1_lyric_address", lyricUri: "http://resource1_lyric_address",
iconUri: "http://resource1_icon_address",
appName: 'MyMusic' appName: 'MyMusic'
} }
}; };
// 启动播放 // 启动播放
aVCastController.start(playItem).then(() => { aVCastController.start(playItem).then(() => {
console.info(`start successfully`); console.info(`start successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -4275,8 +4459,10 @@ getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void ...@@ -4275,8 +4459,10 @@ getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
**示例:** **示例:**
```js ```ts
aVCastController.getCurrentItem(function (err, value) { import { BusinessError } from '@ohos.base';
aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
if (err) { if (err) {
console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -4308,12 +4494,15 @@ getCurrentItem(): Promise\<AVQueueItem> ...@@ -4308,12 +4494,15 @@ getCurrentItem(): Promise\<AVQueueItem>
**示例:** **示例:**
```js ```ts
aVCastController.getCurrentItem().then((AVQueueItem) => { import { BusinessError } from '@ohos.base';
aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
console.info(`getCurrentItem successfully`); console.info(`getCurrentItem successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
### on('playbackStateChange')<sup>10+</sup> ### on('playbackStateChange')<sup>10+</sup>
...@@ -4341,13 +4530,13 @@ on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', c ...@@ -4341,13 +4530,13 @@ on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', c
**示例:** **示例:**
```js ```ts
aVCastController.on('playbackStateChange', 'all', (playbackState) => { aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
console.info(`on playbackStateChange state : ${playbackState.state}`); console.info(`on playbackStateChange state : ${playbackState.state}`);
}); });
let playbackFilter = ['state', 'speed', 'loopMode']; let playbackFilter = ['state', 'speed', 'loopMode'];
aVCastController.on('playbackStateChange', playbackFilter, (playbackState) => { aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
console.info(`on playbackStateChange state : ${playbackState.state}`); console.info(`on playbackStateChange state : ${playbackState.state}`);
}); });
``` ```
...@@ -4376,7 +4565,7 @@ off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): v ...@@ -4376,7 +4565,7 @@ off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): v
**示例:** **示例:**
```js ```ts
aVCastController.off('playbackStateChange'); aVCastController.off('playbackStateChange');
``` ```
...@@ -4404,8 +4593,8 @@ on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void ...@@ -4404,8 +4593,8 @@ on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
**示例:** **示例:**
```js ```ts
aVCastController.on('mediaItemChange', (item) => { aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
console.info(`on mediaItemChange state : ${item.itemId}`); console.info(`on mediaItemChange state : ${item.itemId}`);
}); });
``` ```
...@@ -4433,7 +4622,7 @@ off(type: 'mediaItemChange'): void ...@@ -4433,7 +4622,7 @@ off(type: 'mediaItemChange'): void
**示例:** **示例:**
```js ```ts
aVCastController.off('mediaItemChange'); aVCastController.off('mediaItemChange');
``` ```
...@@ -4461,7 +4650,7 @@ on(type: 'playNext', callback: Callback\<void>): void ...@@ -4461,7 +4650,7 @@ on(type: 'playNext', callback: Callback\<void>): void
**示例:** **示例:**
```js ```ts
aVCastController.on('playNext', () => { aVCastController.on('playNext', () => {
console.info(`on playNext`); console.info(`on playNext`);
}); });
...@@ -4490,7 +4679,7 @@ off(type: 'playNext'): void ...@@ -4490,7 +4679,7 @@ off(type: 'playNext'): void
**示例:** **示例:**
```js ```ts
aVCastController.off('playNext'); aVCastController.off('playNext');
``` ```
...@@ -4518,7 +4707,7 @@ on(type: 'playPrevious', callback: Callback\<void>): void ...@@ -4518,7 +4707,7 @@ on(type: 'playPrevious', callback: Callback\<void>): void
**示例:** **示例:**
```js ```ts
aVCastController.on('playPrevious', () => { aVCastController.on('playPrevious', () => {
console.info(`on playPrevious`); console.info(`on playPrevious`);
}); });
...@@ -4547,7 +4736,7 @@ off(type: 'playPrevious'): void ...@@ -4547,7 +4736,7 @@ off(type: 'playPrevious'): void
**示例:** **示例:**
```js ```ts
aVCastController.off('playPrevious'); aVCastController.off('playPrevious');
``` ```
...@@ -4575,8 +4764,8 @@ on(type: 'seekDone', callback: Callback\<number>): void ...@@ -4575,8 +4764,8 @@ on(type: 'seekDone', callback: Callback\<number>): void
**示例:** **示例:**
```js ```ts
aVCastController.on('seekDone', (pos) => { aVCastController.on('seekDone', (pos: number) => {
console.info(`on seekDone pos:${pos} `); console.info(`on seekDone pos:${pos} `);
}); });
``` ```
...@@ -4604,7 +4793,7 @@ off(type: 'seekDone'): void ...@@ -4604,7 +4793,7 @@ off(type: 'seekDone'): void
**示例:** **示例:**
```js ```ts
aVCastController.off('seekDone'); aVCastController.off('seekDone');
``` ```
...@@ -4626,8 +4815,8 @@ on(type: 'videoSizeChange', callback: (width:number, height:number) => void): vo ...@@ -4626,8 +4815,8 @@ on(type: 'videoSizeChange', callback: (width:number, height:number) => void): vo
**示例:** **示例:**
```js ```ts
aVCastController.on('videoSizeChange', (width, height) => { aVCastController.on('videoSizeChange', (width: number, height: number) => {
console.info(`width :${width} `); console.info(`width :${width} `);
console.info(`height:${height} `); console.info(`height:${height} `);
}); });
...@@ -4650,7 +4839,7 @@ off(type: 'videoSizeChange'): void ...@@ -4650,7 +4839,7 @@ off(type: 'videoSizeChange'): void
**示例:** **示例:**
```js ```ts
aVCastController.off('videoSizeChange'); aVCastController.off('videoSizeChange');
``` ```
...@@ -4684,8 +4873,10 @@ on(type: 'error', callback: ErrorCallback): void ...@@ -4684,8 +4873,10 @@ on(type: 'error', callback: ErrorCallback): void
**示例:** **示例:**
```js ```ts
aVCastController.on('error', (error) => { import { BusinessError } from '@ohos.base'
aVCastController.on('error', (error: BusinessError) => {
console.error('error happened,and error message is :' + error.message) console.error('error happened,and error message is :' + error.message)
console.error('error happened,and error code is :' + error.code) console.error('error happened,and error code is :' + error.code)
}) })
...@@ -4720,7 +4911,7 @@ off(type: 'error'): void ...@@ -4720,7 +4911,7 @@ off(type: 'error'): void
**示例:** **示例:**
```js ```ts
aVCastController.off('error') aVCastController.off('error')
``` ```
...@@ -4942,11 +5133,13 @@ aVCastController.off('error') ...@@ -4942,11 +5133,13 @@ aVCastController.off('error')
**示例:** **示例:**
```js ```ts
let AVSessionController; import { BusinessError } from '@ohos.base';
avSession.createController(currentAVSession.sessionId).then((controller) => {
let AVSessionController: avSession.AVSessionController;
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
AVSessionController = controller; AVSessionController = controller;
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -4976,8 +5169,10 @@ getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void ...@@ -4976,8 +5169,10 @@ getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
**示例:** **示例:**
```js ```ts
avsessionController.getAVPlaybackState(function (err, state) { import { BusinessError } from '@ohos.base';
avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
if (err) { if (err) {
console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5011,10 +5206,12 @@ getAVPlaybackState(): Promise\<AVPlaybackState>; ...@@ -5011,10 +5206,12 @@ getAVPlaybackState(): Promise\<AVPlaybackState>;
**示例:** **示例:**
```js ```ts
avsessionController.getAVPlaybackState().then((state) => { import { BusinessError } from '@ohos.base';
console.info(`getAVPlaybackState : SUCCESS :`);
}).catch((err) => { avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
console.info(`getAVPlaybackState : SUCCESS`);
}).catch((err: BusinessError) => {
console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5043,10 +5240,12 @@ getAVMetadata(): Promise\<AVMetadata> ...@@ -5043,10 +5240,12 @@ getAVMetadata(): Promise\<AVMetadata>
| 6600103 | The session controller does not exist. | | 6600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getAVMetadata().then((metadata) => { import { BusinessError } from '@ohos.base';
avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => {
console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5075,8 +5274,10 @@ getAVMetadata(callback: AsyncCallback\<AVMetadata>): void ...@@ -5075,8 +5274,10 @@ getAVMetadata(callback: AsyncCallback\<AVMetadata>): void
| 6600103 | The session controller does not exist. | | 6600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getAVMetadata(function (err, metadata) { import { BusinessError } from '@ohos.base';
avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
if (err) { if (err) {
console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5109,10 +5310,12 @@ getAVQueueTitle(): Promise\<string> ...@@ -5109,10 +5310,12 @@ getAVQueueTitle(): Promise\<string>
| 6600103 | The session controller does not exist. | | 6600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getAVQueueTitle().then((title) => { import { BusinessError } from '@ohos.base';
avsessionController.getAVQueueTitle().then((title: string) => {
console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5141,8 +5344,10 @@ getAVQueueTitle(callback: AsyncCallback\<string>): void ...@@ -5141,8 +5344,10 @@ getAVQueueTitle(callback: AsyncCallback\<string>): void
| 6600103 | The session controller does not exist. | | 6600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getAVQueueTitle(function (err, title) { import { BusinessError } from '@ohos.base';
avsessionController.getAVQueueTitle((err: BusinessError, title: string) => {
if (err) { if (err) {
console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5175,10 +5380,12 @@ getAVQueueItems(): Promise\<Array\<AVQueueItem>> ...@@ -5175,10 +5380,12 @@ getAVQueueItems(): Promise\<Array\<AVQueueItem>>
| 6600103 | The session controller does not exist. | | 6600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getAVQueueItems().then((items) => { import { BusinessError } from '@ohos.base';
avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5207,8 +5414,10 @@ getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void ...@@ -5207,8 +5414,10 @@ getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void
| 6600103 | The session controller does not exist. | | 6600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getAVQueueItems(function (err, items) { import { BusinessError } from '@ohos.base';
avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
if (err) { if (err) {
console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5248,11 +5457,13 @@ skipToQueueItem(itemId: number): Promise\<void> ...@@ -5248,11 +5457,13 @@ skipToQueueItem(itemId: number): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let queueItemId = 0; let queueItemId = 0;
avsessionController.skipToQueueItem(queueItemId).then(() => { avsessionController.skipToQueueItem(queueItemId).then(() => {
console.info(`SkipToQueueItem successfully`); console.info(`SkipToQueueItem successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5283,9 +5494,11 @@ skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void ...@@ -5283,9 +5494,11 @@ skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
let queueItemId = 0; let queueItemId = 0;
avsessionController.skipToQueueItem(queueItemId, function (err) { avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5318,10 +5531,12 @@ getOutputDevice(): Promise\<OutputDeviceInfo> ...@@ -5318,10 +5531,12 @@ getOutputDevice(): Promise\<OutputDeviceInfo>
| 600103 | The session controller does not exist. | | 600103 | The session controller does not exist. |
**示例:** **示例:**
```js ```ts
avsessionController.getOutputDevice().then((deviceInfo) => { import { BusinessError } from '@ohos.base';
console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`);
}).catch((err) => { avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
console.info(`GetOutputDevice : SUCCESS`);
}).catch((err: BusinessError) => {
console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5350,12 +5565,14 @@ getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void ...@@ -5350,12 +5565,14 @@ getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
**示例:** **示例:**
```js ```ts
avsessionController.getOutputDevice(function (err, deviceInfo) { import { BusinessError } from '@ohos.base';
avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
if (err) { if (err) {
console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); console.info(`GetOutputDevice : SUCCESS`);
} }
}); });
``` ```
...@@ -5393,13 +5610,16 @@ sendAVKeyEvent(event: KeyEvent): Promise\<void> ...@@ -5393,13 +5610,16 @@ sendAVKeyEvent(event: KeyEvent): Promise\<void>
**示例:** **示例:**
```js ```ts
let keyItem = {code:0x49, pressedTime:2, deviceId:0}; import keyEvent from '@ohos.multimodalInput.keyEvent';
let event = {action:2, key:keyItem, keys:[keyItem]}; import { BusinessError } from '@ohos.base';
let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0};
let event: keyEvent.KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avsessionController.sendAVKeyEvent(event).then(() => { avsessionController.sendAVKeyEvent(event).then(() => {
console.info(`SendAVKeyEvent Successfully`); console.info(`SendAVKeyEvent Successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5432,11 +5652,14 @@ sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void ...@@ -5432,11 +5652,14 @@ sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
let keyItem = {code:0x49, pressedTime:2, deviceId:0}; import keyEvent from '@ohos.multimodalInput.keyEvent';
let event = {action:2, key:keyItem, keys:[keyItem]}; import { BusinessError } from '@ohos.base';
let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0};
let event: keyEvent.KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avsessionController.sendAVKeyEvent(event, function (err) { avsessionController.sendAVKeyEvent(event, (err: BusinessError) => {
if (err) { if (err) {
console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5470,10 +5693,12 @@ getLaunchAbility(): Promise\<WantAgent> ...@@ -5470,10 +5693,12 @@ getLaunchAbility(): Promise\<WantAgent>
**示例:** **示例:**
```js ```ts
avsessionController.getLaunchAbility().then((agent) => { import { BusinessError } from '@ohos.base';
avsessionController.getLaunchAbility().then((agent: object) => {
console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5503,8 +5728,10 @@ getLaunchAbility(callback: AsyncCallback\<WantAgent>): void ...@@ -5503,8 +5728,10 @@ getLaunchAbility(callback: AsyncCallback\<WantAgent>): void
**示例:** **示例:**
```js ```ts
avsessionController.getLaunchAbility(function (err, agent) { import { BusinessError } from '@ohos.base';
avsessionController.getLaunchAbility((err: BusinessError, agent: object) => {
if (err) { if (err) {
console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5537,8 +5764,8 @@ getRealPlaybackPositionSync(): number ...@@ -5537,8 +5764,8 @@ getRealPlaybackPositionSync(): number
**示例:** **示例:**
```js ```ts
let time = avsessionController.getRealPlaybackPositionSync(); let time: number = avsessionController.getRealPlaybackPositionSync();
``` ```
### isActive<sup>10+</sup> ### isActive<sup>10+</sup>
...@@ -5566,10 +5793,12 @@ isActive(): Promise\<boolean> ...@@ -5566,10 +5793,12 @@ isActive(): Promise\<boolean>
**示例:** **示例:**
```js ```ts
avsessionController.isActive().then((isActive) => { import { BusinessError } from '@ohos.base';
avsessionController.isActive().then((isActive: boolean) => {
console.info(`IsActive : SUCCESS : isactive : ${isActive}`); console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5599,8 +5828,10 @@ isActive(callback: AsyncCallback\<boolean>): void ...@@ -5599,8 +5828,10 @@ isActive(callback: AsyncCallback\<boolean>): void
**示例:** **示例:**
```js ```ts
avsessionController.isActive(function (err, isActive) { import { BusinessError } from '@ohos.base';
avsessionController.isActive((err: BusinessError, isActive: boolean) => {
if (err) { if (err) {
console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5633,10 +5864,12 @@ destroy(): Promise\<void> ...@@ -5633,10 +5864,12 @@ destroy(): Promise\<void>
**示例:** **示例:**
```js ```ts
import { BusinessError } from '@ohos.base';
avsessionController.destroy().then(() => { avsessionController.destroy().then(() => {
console.info(`Destroy : SUCCESS `); console.info(`Destroy : SUCCESS `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5665,8 +5898,10 @@ destroy(callback: AsyncCallback\<void>): void ...@@ -5665,8 +5898,10 @@ destroy(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```ts
avsessionController.destroy(function (err) { import { BusinessError } from '@ohos.base';
avsessionController.destroy((err: BusinessError) => {
if (err) { if (err) {
console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5700,10 +5935,12 @@ getValidCommands(): Promise\<Array\<AVControlCommandType>> ...@@ -5700,10 +5935,12 @@ getValidCommands(): Promise\<Array\<AVControlCommandType>>
**示例:** **示例:**
```js ```ts
avsessionController.getValidCommands.then((validCommands) => { import { BusinessError } from '@ohos.base';
avsessionController.getValidCommands.then((validCommands: avSession.AVControlCommandType[]) => {
console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5733,8 +5970,10 @@ getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void ...@@ -5733,8 +5970,10 @@ getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void
**示例:** **示例:**
```js ```ts
avsessionController.getValidCommands(function (err, validCommands) { import { BusinessError } from '@ohos.base';
avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
if (err) { if (err) {
console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5781,8 +6020,11 @@ sendControlCommand(command: AVControlCommand): Promise\<void> ...@@ -5781,8 +6020,11 @@ sendControlCommand(command: AVControlCommand): Promise\<void>
**示例:** **示例:**
```js ```ts
let avCommand = {command:'play'}; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avCommand: avSession.AVControlCommand = {command:'play'};
// let avCommand = {command:'pause'}; // let avCommand = {command:'pause'};
// let avCommand = {command:'stop'}; // let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'}; // let avCommand = {command:'playNext'};
...@@ -5795,7 +6037,7 @@ let avCommand = {command:'play'}; ...@@ -5795,7 +6037,7 @@ let avCommand = {command:'play'};
// let avCommand = {command:'toggleFavorite', parameter:"false"}; // let avCommand = {command:'toggleFavorite', parameter:"false"};
avsessionController.sendControlCommand(avCommand).then(() => { avsessionController.sendControlCommand(avCommand).then(() => {
console.info(`SendControlCommand successfully`); console.info(`SendControlCommand successfully`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -5833,8 +6075,11 @@ sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): v ...@@ -5833,8 +6075,11 @@ sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): v
**示例:** **示例:**
```js ```ts
let avCommand = {command:'play'}; import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avCommand: avSession.AVControlCommand = {command:'play'};
// let avCommand = {command:'pause'}; // let avCommand = {command:'pause'};
// let avCommand = {command:'stop'}; // let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'}; // let avCommand = {command:'playNext'};
...@@ -5845,7 +6090,7 @@ let avCommand = {command:'play'}; ...@@ -5845,7 +6090,7 @@ let avCommand = {command:'play'};
// let avCommand = {command:'setSpeed', parameter:2.6}; // let avCommand = {command:'setSpeed', parameter:2.6};
// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let avCommand = {command:'toggleFavorite', parameter:"false"}; // let avCommand = {command:'toggleFavorite', parameter:"false"};
avsessionController.sendControlCommand(avCommand, function (err) { avsessionController.sendControlCommand(avCommand, (err: BusinessError) => {
if (err) { if (err) {
console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -5892,12 +6137,32 @@ sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void ...@@ -5892,12 +6137,32 @@ sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avSessionController: avSession.AVSessionController;
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
avSessionController = controller;
}).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});
let commandName = "my_command"; let commandName = "my_command";
let args = { avSessionController.sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
command : "This is my command" console.info(`SendCommonCommand successfully`);
} }).catch((err: BusinessError) => {
avsessionController.sendCommonCommand(commandName, args).catch((err) => {
console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
}) })
``` ```
...@@ -5935,12 +6200,29 @@ sendCommonCommand(command: string, args: {[key: string]: Object}, callback: Asyn ...@@ -5935,12 +6200,29 @@ sendCommonCommand(command: string, args: {[key: string]: Object}, callback: Asyn
**示例:** **示例:**
```js ```ts
import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avSessionController: avSession.AVSessionController;
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
avSessionController = controller;
}).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});
let commandName = "my_command"; let commandName = "my_command";
let args = { avSessionController.sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
command : "This is my command"
}
avsessionController.sendCommonCommand(commandName, args, (err) => {
if(err) { if(err) {
console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
} }
...@@ -5973,8 +6255,31 @@ getExtras(): Promise\<{[key: string]: Object}> ...@@ -5973,8 +6255,31 @@ getExtras(): Promise\<{[key: string]: Object}>
| 6600107 | Too many commands or events. | | 6600107 | Too many commands or events. |
**示例:** **示例:**
```js ```ts
let extras = await avsessionController.getExtras().catch((err) => { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avSessionController: avSession.AVSessionController;
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
avSessionController = controller;
}).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});
avSessionController.getExtras().then((extras) => {
console.info(`getExtras : SUCCESS : ${extras}`);
}).catch((err: BusinessError) => {
console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -6005,12 +6310,33 @@ getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void ...@@ -6005,12 +6310,33 @@ getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
| 6600107 | Too many commands or events. | | 6600107 | Too many commands or events. |
**示例:** **示例:**
```js ```ts
avsessionController.getExtras(function (err, extras) { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avSessionController: avSession.AVSessionController;
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
avSessionController = controller;
}).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});
avSessionController.getExtras((err, extras) => {
if (err) { if (err) {
console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info(`getExtras : SUCCESS : assetId : ${extras}`); console.info(`getExtras : SUCCESS : ${extras}`);
} }
}); });
``` ```
...@@ -6041,15 +6367,15 @@ on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: ( ...@@ -6041,15 +6367,15 @@ on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (
**示例:** **示例:**
```js ```ts
avsessionController.on('metadataChange', 'all', (metadata) => { avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
console.info(`on metadataChange assetId : ${metadata.assetId}`); console.info(`on metadataChange assetId : ${metadata.assetId}`);
}); });
let metaFilter = ['assetId', 'title', 'description']; avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
avsessionController.on('metadataChange', metaFilter, (metadata) => {
console.info(`on metadataChange assetId : ${metadata.assetId}`); console.info(`on metadataChange assetId : ${metadata.assetId}`);
}); });
``` ```
### off('metadataChange')<sup>10+</sup> ### off('metadataChange')<sup>10+</sup>
...@@ -6077,7 +6403,7 @@ off(type: 'metadataChange', callback?: (data: AVMetadata) => void) ...@@ -6077,7 +6403,7 @@ off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
**示例:** **示例:**
```js ```ts
avsessionController.off('metadataChange'); avsessionController.off('metadataChange');
``` ```
...@@ -6107,13 +6433,12 @@ on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', c ...@@ -6107,13 +6433,12 @@ on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', c
**示例:** **示例:**
```js ```ts
avsessionController.on('playbackStateChange', 'all', (playbackState) => { avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
console.info(`on playbackStateChange state : ${playbackState.state}`); console.info(`on playbackStateChange state : ${playbackState.state}`);
}); });
let playbackFilter = ['state', 'speed', 'loopMode']; avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
avsessionController.on('playbackStateChange', playbackFilter, (playbackState) => {
console.info(`on playbackStateChange state : ${playbackState.state}`); console.info(`on playbackStateChange state : ${playbackState.state}`);
}); });
``` ```
...@@ -6143,7 +6468,7 @@ off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) ...@@ -6143,7 +6468,7 @@ off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
**示例:** **示例:**
```js ```ts
avsessionController.off('playbackStateChange'); avsessionController.off('playbackStateChange');
``` ```
...@@ -6172,7 +6497,7 @@ on(type: 'sessionDestroy', callback: () => void) ...@@ -6172,7 +6497,7 @@ on(type: 'sessionDestroy', callback: () => void)
**示例:** **示例:**
```js ```ts
avsessionController.on('sessionDestroy', () => { avsessionController.on('sessionDestroy', () => {
console.info(`on sessionDestroy : SUCCESS `); console.info(`on sessionDestroy : SUCCESS `);
}); });
...@@ -6203,7 +6528,7 @@ off(type: 'sessionDestroy', callback?: () => void) ...@@ -6203,7 +6528,7 @@ off(type: 'sessionDestroy', callback?: () => void)
**示例:** **示例:**
```js ```ts
avsessionController.off('sessionDestroy'); avsessionController.off('sessionDestroy');
``` ```
...@@ -6232,8 +6557,8 @@ on(type: 'activeStateChange', callback: (isActive: boolean) => void) ...@@ -6232,8 +6557,8 @@ on(type: 'activeStateChange', callback: (isActive: boolean) => void)
**示例:** **示例:**
```js ```ts
avsessionController.on('activeStateChange', (isActive) => { avsessionController.on('activeStateChange', (isActive: boolean) => {
console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
}); });
``` ```
...@@ -6263,7 +6588,7 @@ off(type: 'activeStateChange', callback?: (isActive: boolean) => void) ...@@ -6263,7 +6588,7 @@ off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
**示例:** **示例:**
```js ```ts
avsessionController.off('activeStateChange'); avsessionController.off('activeStateChange');
``` ```
...@@ -6292,9 +6617,9 @@ on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType> ...@@ -6292,9 +6617,9 @@ on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>
**示例:** **示例:**
```js ```ts
avsessionController.on('validCommandChange', (validCommands) => { avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`); console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
}); });
``` ```
...@@ -6324,7 +6649,7 @@ off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandTyp ...@@ -6324,7 +6649,7 @@ off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandTyp
**示例:** **示例:**
```js ```ts
avsessionController.off('validCommandChange'); avsessionController.off('validCommandChange');
``` ```
...@@ -6353,8 +6678,8 @@ on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: Output ...@@ -6353,8 +6678,8 @@ on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: Output
**示例:** **示例:**
```js ```ts
avsessionController.on('outputDeviceChange', (state, device) => { avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
console.info(`on outputDeviceChange state: ${state}, device : ${device}`); console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
}); });
``` ```
...@@ -6384,7 +6709,7 @@ off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: Outp ...@@ -6384,7 +6709,7 @@ off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: Outp
**示例:** **示例:**
```js ```ts
avsessionController.off('outputDeviceChange'); avsessionController.off('outputDeviceChange');
``` ```
...@@ -6414,8 +6739,29 @@ on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: O ...@@ -6414,8 +6739,29 @@ on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: O
**示例:** **示例:**
```js ```ts
avsessionController.on('sessionEvent', (sessionEvent, args) => { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avSessionController: avSession.AVSessionController;
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
avSessionController = controller;
}).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});
avSessionController.on('sessionEvent', (sessionEvent, args) => {
console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
}); });
``` ```
...@@ -6445,7 +6791,7 @@ off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: ...@@ -6445,7 +6791,7 @@ off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]:
**示例:** **示例:**
```js ```ts
avsessionController.off('sessionEvent'); avsessionController.off('sessionEvent');
``` ```
...@@ -6474,8 +6820,8 @@ on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem1 ...@@ -6474,8 +6820,8 @@ on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem1
**示例:** **示例:**
```js ```ts
avsessionController.on('queueItemsChange', (items) => { avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
console.info(`OnQueueItemsChange, items length is ${items.length}`); console.info(`OnQueueItemsChange, items length is ${items.length}`);
}); });
``` ```
...@@ -6505,7 +6851,7 @@ off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueite ...@@ -6505,7 +6851,7 @@ off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueite
**示例:** **示例:**
```js ```ts
avsessionController.off('queueItemsChange'); avsessionController.off('queueItemsChange');
``` ```
...@@ -6534,8 +6880,8 @@ on(type: 'queueTitleChange', callback: (title: string) => void): void ...@@ -6534,8 +6880,8 @@ on(type: 'queueTitleChange', callback: (title: string) => void): void
**示例:** **示例:**
```js ```ts
avsessionController.on('queueTitleChange', (title) => { avsessionController.on('queueTitleChange', (title: string) => {
console.info(`queueTitleChange, title is ${title}`); console.info(`queueTitleChange, title is ${title}`);
}); });
``` ```
...@@ -6565,7 +6911,7 @@ off(type: 'queueTitleChange', callback?: (title: string) => void): void ...@@ -6565,7 +6911,7 @@ off(type: 'queueTitleChange', callback?: (title: string) => void): void
**示例:** **示例:**
```js ```ts
avsessionController.off('queueTitleChange'); avsessionController.off('queueTitleChange');
``` ```
...@@ -6594,8 +6940,29 @@ on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): vo ...@@ -6594,8 +6940,29 @@ on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): vo
**示例:** **示例:**
```js ```ts
avsessionController.on('extrasChange', (extras) => { import avSession from '@ohos.multimedia.avsession';
import { BusinessError } from '@ohos.base';
let avSessionController: avSession.AVSessionController;
let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = this.context;
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
}
});
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
avSessionController = controller;
}).catch((err: BusinessError) => {
console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});
avSessionController.on('extrasChange', (extras) => {
console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
}); });
``` ```
...@@ -6625,7 +6992,7 @@ off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): ...@@ -6625,7 +6992,7 @@ off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void):
**示例:** **示例:**
```js ```ts
avsessionController.off('extrasChange'); avsessionController.off('extrasChange');
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册