From 755cf062a63ea5f43f4dcd7cb7f2193a27dc6280 Mon Sep 17 00:00:00 2001 From: jiaoyanlin3 Date: Tue, 1 Aug 2023 17:07:27 +0800 Subject: [PATCH] Modification of avsession sample code issues Signed-off-by: jiaoyanlin3 --- .../reference/apis/js-apis-avsession.md | 165 +++++++++++++++--- 1 file changed, 145 insertions(+), 20 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-avsession.md b/zh-cn/application-dev/reference/apis/js-apis-avsession.md index 08a231c2db..ff43b8196f 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-avsession.md +++ b/zh-cn/application-dev/reference/apis/js-apis-avsession.md @@ -327,11 +327,27 @@ createController(sessionId: string): Promise\ **示例:** ```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\; **示例:** ```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: sessionId, + sessionId: currSessionId, } let castDevice; avSession.on('deviceAvailable', (device) => { @@ -1432,8 +1516,25 @@ startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\ **示例:** ```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: sessionId, + sessionId: currSessionId, } let castDevice; avSession.on('deviceAvailable', (device) => { @@ -1474,15 +1575,27 @@ stopCasting(session: SessionToken, callback: AsyncCallback\): 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: sessionId, + sessionId: currSessionId, } -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\ **示例:** ```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: sessionId, + sessionId: currSessionId, } -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}`); } }); ``` -- GitLab