Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
4bd7ca8e
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4bd7ca8e
编写于
11月 30, 2022
作者:
D
dingdongdong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify avsession.md
Signed-off-by:
N
dingdongdong
<
dingdongdong4@huawei.com
>
上级
212dc211
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
69 addition
and
29 deletion
+69
-29
zh-cn/application-dev/reference/apis/js-apis-avsession.md
zh-cn/application-dev/reference/apis/js-apis-avsession.md
+69
-29
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-avsession.md
浏览文件 @
4bd7ca8e
# 媒体会话管理
# 媒体会话管理
媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。
媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。
...
@@ -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
P
laybackState
=
{
let
p
laybackState
=
{
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
(
P
laybackState
).
then
(()
=>
{
session
.
setAVPlaybackState
(
p
laybackState
).
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录