From 87346957120ad2bc80649ce6027d2ae1817254fc Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Fri, 15 Nov 2024 15:37:54 +0800 Subject: [PATCH] =?UTF-8?q?[audio]=E6=B7=BB=E5=8A=A0=E9=9F=B3=E9=A2=91?= =?UTF-8?q?=E8=B7=AF=E5=BE=84env=E7=A4=BA=E4=BE=8B=E4=B8=8E=E5=A4=9A?= =?UTF-8?q?=E9=9F=B3=E9=A2=91=E5=90=8C=E6=97=B6=E6=92=AD=E6=94=BE=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 6 ++ .../create-inner-audio-context.uvue | 3 + .../inner-audio-mult.uvue | 92 +++++++++++++++++++ .../inner-audio-path.uvue | 38 +++++++- 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 pages/API/create-inner-audio-context/inner-audio-mult.uvue diff --git a/pages.json b/pages.json index 3ef35ee1..6dfacdf4 100644 --- a/pages.json +++ b/pages.json @@ -1125,6 +1125,12 @@ "navigationBarTitleText": "inner-audio-path" } }, + { + "path": "pages/API/create-inner-audio-context/inner-audio-mult", + "style": { + "navigationBarTitleText": "inner-audio-mult" + } + }, // #endif // #ifdef WEB || MP { diff --git a/pages/API/create-inner-audio-context/create-inner-audio-context.uvue b/pages/API/create-inner-audio-context/create-inner-audio-context.uvue index d1a67162..e9be8754 100644 --- a/pages/API/create-inner-audio-context/create-inner-audio-context.uvue +++ b/pages/API/create-inner-audio-context/create-inner-audio-context.uvue @@ -63,6 +63,9 @@ + + + diff --git a/pages/API/create-inner-audio-context/inner-audio-mult.uvue b/pages/API/create-inner-audio-context/inner-audio-mult.uvue new file mode 100644 index 00000000..dc1ee160 --- /dev/null +++ b/pages/API/create-inner-audio-context/inner-audio-mult.uvue @@ -0,0 +1,92 @@ + + + + + \ No newline at end of file diff --git a/pages/API/create-inner-audio-context/inner-audio-path.uvue b/pages/API/create-inner-audio-context/inner-audio-path.uvue index bf769c36..42d12843 100644 --- a/pages/API/create-inner-audio-context/inner-audio-path.uvue +++ b/pages/API/create-inner-audio-context/inner-audio-path.uvue @@ -22,7 +22,9 @@ return { title: 'audio-path', playIndex: 0, - isPlaying: false, + isPlaying: false, + nativePath:uni.env.CACHE_PATH+'uni-audio/test/test.mp3' as string, + sdcardPath :'sdcard/uni-audio/test.mp3', _audioContext: null as InnerAudioContext | null, supportPaths: [ { @@ -32,7 +34,11 @@ { description: '本地路径:../static/', src: '../../../static/test-audio/ForElise.mp3' - }, + }, + { + description: '本地路径:env方式', + src: 'env' + }, { description: '网络路径', src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3' @@ -60,8 +66,26 @@ this._audioContext!.onError((err) => { this.isPlaying = false; console.log('err', err); - }); - }, + }); + + const fileManager = uni.getFileSystemManager() + try { + fileManager.rmdirSync(uni.env.CACHE_PATH+'uni-audio/test',true) + } catch (e) { + } + + try { + fileManager.mkdirSync(uni.env.CACHE_PATH+'uni-audio/test',true) + } catch (e) { + } + try{ + fileManager.copyFileSync( + '/static/test-audio/ForElise.mp3', + this.nativePath) + } catch(e){ + } + }, + onUnload() { if (this._audioContext != null) { this.pause(); @@ -78,7 +102,11 @@ if (this.isPlaying && this.playIndex == index) { this.pause(); return; - } + } + if(audioUrl == 'env'){ + audioUrl=this.nativePath + } + this.playIndex = index this._audioContext!.src = audioUrl; this._audioContext!.play(); -- GitLab