From f835b095780efa14332efffcfe9508933d47415c Mon Sep 17 00:00:00 2001 From: jiao_yanlin Date: Mon, 19 Sep 2022 16:57:25 +0800 Subject: [PATCH] Sample code error modification Signed-off-by: jiao_yanlin --- .../reference/apis/js-apis-audio.md | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-audio.md b/zh-cn/application-dev/reference/apis/js-apis-audio.md index d7c676c0fd..8e4140b0a3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-audio.md +++ b/zh-cn/application-dev/reference/apis/js-apis-audio.md @@ -774,12 +774,15 @@ getRoutingManager(): Promise<AudioRoutingManager> **示例:** ```js -await audioManager.getRoutingManager().then((value) => { - var routingManager = value; - console.info('getRoutingManager Promise SUCCESS.'); -}).catch((err) => { - console.error(`Result ERROR: ${err}`); -}); +var audioManager = audio.getAudioManager(); +async function getRoutingManager(){ + await audioManager.getRoutingManager().then((value) => { + var routingManager = value; + console.info('getRoutingManager Promise SUCCESS.'); + }).catch((err) => { + console.error(`Result ERROR: ${err}`); + }); +} ``` ### setVolume @@ -4246,7 +4249,10 @@ audioRenderer.getBufferSize().then((data)=> { }); console.info(`Buffer size: ${bufferSize}`); var context = featureAbility.getContext(); -var path = await context.getCacheDir(); +var path; +async function getCacheDir(){ + path = await context.getCacheDir(); +} var filePath = path + '/StarWars10s-2C-48000-4SW.wav'; let ss = fileio.createStreamSync(filePath, 'r'); let buf = new ArrayBuffer(bufferSize); @@ -4314,7 +4320,9 @@ audioRenderer.getBufferSize().then((data) => { }); console.info(`BufferSize: ${bufferSize}`); var context = featureAbility.getContext(); -var path = await context.getCacheDir(); +async function getCacheDir(){ + path = await context.getCacheDir(); +} var filePath = 'data/StarWars10s-2C-48000-4SW.wav'; let ss = fileio.createStreamSync(filePath, 'r'); let buf = new ArrayBuffer(bufferSize); @@ -4593,7 +4601,11 @@ var audioRendererOptions = { streamInfo: audioStreamInfo, rendererInfo: audioRendererInfo } -let audioRenderer = await audio.createAudioRenderer(audioRendererOptions); +let audioRenderer; +async function createAudioRenderer(){ + audioRenderer = await audio.createAudioRenderer(audioRendererOptions); +} + let mode = 0; audioRenderer.setInterruptMode(mode).then(data=>{ console.info('setInterruptMode Success!'); @@ -4634,7 +4646,12 @@ var audioRendererOptions = { streamInfo: audioStreamInfo, rendererInfo: audioRendererInfo } -let audioRenderer = await audio.createAudioRenderer(audioRendererOptions); + +let audioRenderer; +async function createAudioRenderer(){ + audioRenderer = await audio.createAudioRenderer(audioRendererOptions); +} + let mode = 1; audioRenderer.setInterruptMode(mode, (err, data)=>{ if(err){ -- GitLab