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 b0070938d00f82b6b1402da62bff0041f6997800..cc27fe0dc794990840ad13d787e1cd8de6e36c4d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-audio.md +++ b/zh-cn/application-dev/reference/apis/js-apis-audio.md @@ -4862,10 +4862,10 @@ async function getCacheDir(){ } let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY); -let currStat = await fs.stat(path); -let buf = new ArrayBuffer(bufferSize); -let len = currStat.size % bufferSize == 0 ? Math.floor(currStat.size / bufferSize) : Math.floor(currStat.size / bufferSize + 1); -for (let i = 0;i < len; i++) { +fs.stat(path).then((stat) => { + let buf = new ArrayBuffer(bufferSize); + let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1); + for (let i = 0;i < len; i++) { let options = { offset: i * bufferSize, length: bufferSize @@ -4880,7 +4880,9 @@ for (let i = 0;i < len; i++) { } }) }) -} + } +}); + ``` @@ -4916,21 +4918,22 @@ async function getCacheDir(){ } let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY); -let currStat = await fs.stat(path); -let buf = new ArrayBuffer(bufferSize); -let len = currStat.size % bufferSize == 0 ? Math.floor(currStat.size / bufferSize) : Math.floor(currStat.size / bufferSize + 1); -for (let i = 0;i < len; i++) { - let options = { - offset: i * bufferSize, - length: bufferSize - } - let readsize = await fs.read(file.fd, buf, options) - try{ - let writeSize = await audioRenderer.write(buf); - } catch(err) { - console.error(`audioRenderer.write err: ${err}`); - } -} +fs.stat(path).then((stat) => { + let buf = new ArrayBuffer(bufferSize); + let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1); + for (let i = 0;i < len; i++) { + let options = { + offset: i * bufferSize, + length: bufferSize + } + let readsize = await fs.read(file.fd, buf, options) + try{ + let writeSize = await audioRenderer.write(buf); + } catch(err) { + console.error(`audioRenderer.write err: ${err}`); + } + } +}); ``` ### getAudioTime8+