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

js-api-avsession arkts整改

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