You need to sign in or sign up before continuing.
提交 4bd7ca8e 编写于 作者: D dingdongdong

modify avsession.md

Signed-off-by: Ndingdongdong <dingdongdong4@huawei.com>
上级 212dc211
# 媒体会话管理 # 媒体会话管理
媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。 媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。
...@@ -54,9 +54,10 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -54,9 +54,10 @@ import featureAbility from '@ohos.ability.featureAbility';
let session; let session;
let tag = "createNewSession"; let tag = "createNewSession";
let type = "audio";
let context = featureAbility.getContext(); let context = featureAbility.getContext();
await avSession.createAVSession(context, tag, "audio").then((data) => { await avSession.createAVSession(context, tag, type).then((data) => {
session = data; session = data;
console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
}).catch((err) => { }).catch((err) => {
...@@ -95,9 +96,10 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -95,9 +96,10 @@ import featureAbility from '@ohos.ability.featureAbility';
let session; let session;
let tag = "createNewSession"; let tag = "createNewSession";
let type = "audio";
let context = featureAbility.getContext(); let context = featureAbility.getContext();
avSession.createAVSession(context, tag, "audio", function (err, data) { avSession.createAVSession(context, tag, type, function (err, data) {
if (err) { if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else { } else {
...@@ -224,6 +226,20 @@ createController(sessionId: string): Promise\<AVSessionController> ...@@ -224,6 +226,20 @@ createController(sessionId: string): Promise\<AVSessionController>
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let session;
let tag = "createNewSession";
let type = "audio";
let context = featureAbility.getContext();
await avSession.createAVSession(context, tag, type).then((data) => {
session = data;
console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
}).catch((err) => {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
});
let controller; let controller;
await avSession.createController(session.sessionId).then((avcontroller) => { await avSession.createController(session.sessionId).then((avcontroller) => {
controller = avcontroller; controller = avcontroller;
...@@ -263,6 +279,20 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController ...@@ -263,6 +279,20 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController
**示例:** **示例:**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let session;
let tag = "createNewSession";
let type = "audio";
let context = featureAbility.getContext();
await avSession.createAVSession(context, tag, type).then((data) => {
session = data;
console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
}).catch((err) => {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
});
let controller; let controller;
avSession.createController(session.sessionId, function (err, avcontroller) { avSession.createController(session.sessionId, function (err, avcontroller) {
if (err) { if (err) {
...@@ -562,7 +592,7 @@ sendSystemAVKeyEvent(event: KeyEvent): Promise\<void> ...@@ -562,7 +592,7 @@ sendSystemAVKeyEvent(event: KeyEvent): Promise\<void>
```js ```js
let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let keyItem = {code:0x49, pressedTime:2, deviceId:0};
let event = {action:2, key:keyItem, keys:[keyItem]}; let event = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avSession.sendSystemAVKeyEvent(event).then(() => { avSession.sendSystemAVKeyEvent(event).then(() => {
console.info('SendSystemAVKeyEvent Successfully'); console.info('SendSystemAVKeyEvent Successfully');
...@@ -603,7 +633,7 @@ sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void ...@@ -603,7 +633,7 @@ sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
```js ```js
let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let keyItem = {code:0x49, pressedTime:2, deviceId:0};
let event = {action:2, key:keyItem, keys:[keyItem]}; let event = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avSession.sendSystemAVKeyEvent(event, function (err) { avSession.sendSystemAVKeyEvent(event, function (err) {
if (err) { if (err) {
...@@ -650,17 +680,22 @@ sendSystemControlCommand(command: AVControlCommand): Promise\<void> ...@@ -650,17 +680,22 @@ sendSystemControlCommand(command: AVControlCommand): Promise\<void>
**示例:** **示例:**
```js ```js
let avcommand = {command:'play'}; let cmd : avSession.AVControlCommandType = 'play';
// let avcommand = {command:'pause'}; // let cmd : avSession.AVControlCommandType = 'pause';
// let avcommand = {command:'stop'}; // let cmd : avSession.AVControlCommandType = 'stop';
// let avcommand = {command:'playNext'}; // let cmd : avSession.AVControlCommandType = 'playNext';
// let avcommand = {command:'playPrevious'}; // let cmd : avSession.AVControlCommandType = 'playPrevious';
// let avcommand = {command:'fastForward'}; // let cmd : avSession.AVControlCommandType = 'fastForward';
// let avcommand = {command:'rewind'}; // let cmd : avSession.AVControlCommandType = 'rewind';
// let avcommand = {command:'seek', parameter:10}; let avcommand = {command:cmd};
// let avcommand = {command:'setSpeed', parameter:2.6}; // let cmd : avSession.AVControlCommandType = 'seek';
// let avcommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let avcommand = {command:cmd, parameter:10};
// let avcommand = {command:'toggleFavorite', parameter:"false"}; // let cmd : avSession.AVControlCommandType = 'setSpeed';
// let avcommand = {command:cmd, parameter:2.6};
// let cmd : avSession.AVControlCommandType = 'setLoopMode';
// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
// let avcommand = {command:cmd, parameter:"false"};
avSession.sendSystemControlCommand(avcommand).then(() => { avSession.sendSystemControlCommand(avcommand).then(() => {
console.info('SendSystemControlCommand successfully'); console.info('SendSystemControlCommand successfully');
}).catch((err) => { }).catch((err) => {
...@@ -699,17 +734,22 @@ sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<voi ...@@ -699,17 +734,22 @@ sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<voi
**示例:** **示例:**
```js ```js
let avcommand = {command:'play'}; let cmd : avSession.AVControlCommandType = 'play';
// let avcommand = {command:'pause'}; // let cmd : avSession.AVControlCommandType = 'pause';
// let avcommand = {command:'stop'}; // let cmd : avSession.AVControlCommandType = 'stop';
// let avcommand = {command:'playNext'}; // let cmd : avSession.AVControlCommandType = 'playNext';
// let avcommand = {command:'playPrevious'}; // let cmd : avSession.AVControlCommandType = 'playPrevious';
// let avcommand = {command:'fastForward'}; // let cmd : avSession.AVControlCommandType = 'fastForward';
// let avcommand = {command:'rewind'}; // let cmd : avSession.AVControlCommandType = 'rewind';
// let avcommand = {command:'seek', parameter:10}; let avcommand = {command:cmd};
// let avcommand = {command:'setSpeed', parameter:2.6}; // let cmd : avSession.AVControlCommandType = 'seek';
// let avcommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let avcommand = {command:cmd, parameter:10};
// let avcommand = {command:'toggleFavorite', parameter:"false"}; // let cmd : avSession.AVControlCommandType = 'setSpeed';
// let avcommand = {command:cmd, parameter:2.6};
// let cmd : avSession.AVControlCommandType = 'setLoopMode';
// 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, function (err) {
if (err) { if (err) {
console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
...@@ -874,7 +914,7 @@ setAVPlaybackState(state: AVPlaybackState): Promise\<void> ...@@ -874,7 +914,7 @@ setAVPlaybackState(state: AVPlaybackState): Promise\<void>
**示例:** **示例:**
```js ```js
let PlaybackState = { let playbackState = {
state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
speed: 1.0, speed: 1.0,
position:{elapsedTime:10, updateTime:(new Date()).getTime()}, position:{elapsedTime:10, updateTime:(new Date()).getTime()},
...@@ -882,7 +922,7 @@ let PlaybackState = { ...@@ -882,7 +922,7 @@ let PlaybackState = {
loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
isFavorite:true, isFavorite:true,
}; };
session.setAVPlaybackState(PlaybackState).then(() => { session.setAVPlaybackState(playbackState).then(() => {
console.info('SetAVPlaybackState successfully'); console.info('SetAVPlaybackState successfully');
}).catch((err) => { }).catch((err) => {
console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册