Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
755cf062
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,发现更多精彩内容 >>
提交
755cf062
编写于
8月 01, 2023
作者:
J
jiaoyanlin3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modification of avsession sample code issues
Signed-off-by:
N
jiaoyanlin3
<
jiaoyanlin3@huawei.com
>
上级
1e031aa0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
145 addition
and
20 deletion
+145
-20
zh-cn/application-dev/reference/apis/js-apis-avsession.md
zh-cn/application-dev/reference/apis/js-apis-avsession.md
+145
-20
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-avsession.md
浏览文件 @
755cf062
...
...
@@ -327,11 +327,27 @@ createController(sessionId: string): Promise\<AVSessionController>
**示例:**
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
currentAVSession
;
let
tag
=
"
createNewSession
"
;
let
context
=
featureAbility
.
getContext
();
let
sessionId
;
//供后续函数入参使用
avSession
.
createAVSession
(
context
,
tag
,
"
audio
"
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
info
(
`CreateAVSession BusinessError: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
}
else
{
currentAVSession
=
data
;
sessionId
=
currentAVSession
.
sessionId
;
console
.
info
(
`CreateAVSession : SUCCESS : sessionId =
${
sessionId
}
`
);
}
});
let
currentAVcontroller
;
avSession
.
createController
(
currentAVSession
.
sessionId
).
then
((
avcontroller
)
=>
{
avSession
.
createController
(
sessionId
).
then
((
avcontroller
)
=>
{
currentAVcontroller
=
avcontroller
;
console
.
info
(
`CreateController : SUCCESS :
${
currentAVcontroller
.
sessionId
}
`
);
console
.
info
(
'
CreateController : SUCCESS
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`CreateController BusinessError: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
});
...
...
@@ -367,13 +383,30 @@ createController(sessionId: string, callback: AsyncCallback\<AVSessionController
**示例:**
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
currentAVSession
;
let
tag
=
"
createNewSession
"
;
let
context
=
featureAbility
.
getContext
();
let
sessionId
;
//供后续函数入参使用
avSession
.
createAVSession
(
context
,
tag
,
"
audio
"
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
info
(
`CreateAVSession BusinessError: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
}
else
{
currentAVSession
=
data
;
sessionId
=
currentAVSession
.
sessionId
;
console
.
info
(
`CreateAVSession : SUCCESS : sessionId =
${
sessionId
}
`
);
}
});
let
currentAVcontroller
;
avSession
.
createController
(
currentAVSession
.
sessionId
,
function
(
err
,
avcontroller
)
{
avSession
.
createController
(
sessionId
,
function
(
err
,
avcontroller
)
{
if
(
err
)
{
console
.
error
(
`CreateController BusinessError: code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
}
else
{
currentAVcontroller
=
avcontroller
;
console
.
info
(
`CreateController : SUCCESS :
${
currentAVcontroller
.
sessionId
}
`
);
console
.
info
(
'
CreateController : SUCCESS
'
);
}
});
```
...
...
@@ -1293,6 +1326,23 @@ getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}
});
let aVCastController;
avSession.getAVCastController(sessionId ,function (err, avcontroller) {
if (err) {
...
...
@@ -1339,6 +1389,23 @@ getAVCastController(sessionId: string): Promise\<AVCastController>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
sessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}
});
let aVCastController;
avSession.getAVCastController(sessionId).then((avcontroller) => {
aVCastController = avcontroller;
...
...
@@ -1379,8 +1446,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCal
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = {
sessionId:
s
essionId,
sessionId:
currS
essionId,
}
let castDevice;
avSession.on('deviceAvailable', (device) => {
...
...
@@ -1432,8 +1516,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = {
sessionId:
s
essionId,
sessionId:
currS
essionId,
}
let castDevice;
avSession.on('deviceAvailable', (device) => {
...
...
@@ -1474,15 +1575,27 @@ stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = {
sessionId:
s
essionId,
sessionId:
currS
essionId,
}
let castDevice;
avSession.on('deviceAvailable', (device) => {
castDevice = device;
console.info(`on deviceAvailable : ${device} `);
});
avSession.stopCasting(myToken, castDevice, function (err) {
avSession.stopCasting(myToken, function (err) {
if (err) {
console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
...
...
@@ -1523,14 +1636,26 @@ stopCasting(session: SessionToken): Promise\<void>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility';
let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; //供后续函数入参使用
avSession.createAVSession(context, tag, "audio", function (err, data) {
if (err) {
console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
currentAVSession = data;
currSessionId = currentAVSession.sessionId;
console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
}
});
let myToken = {
sessionId:
s
essionId,
sessionId:
currS
essionId,
}
let castDevice;
avSession.on('deviceAvailable', (device) => {
castDevice = device;
console.info(`on deviceAvailable : ${device} `);
});
avSession.stopCasting(myToken).then(() => {
console.info(`stopCasting successfully`);
}).catch((err) => {
...
...
@@ -5885,7 +6010,7 @@ avsessionController.getExtras(function (err, extras) {
if (err) {
console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
} else {
console.info(`getExtras : SUCCESS : assetId : ${
metadata.assetId
}`);
console.info(`getExtras : SUCCESS : assetId : ${
extras
}`);
}
});
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录