提交 8e9b079d 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

修改 inner-audio-path 示例。

上级 1bd26566
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
title: 'audio-path', title: 'audio-path',
playIndex: 0, playIndex: 0,
isPlaying: false, isPlaying: false,
nativePath:uni.env.CACHE_PATH+'uni-audio/test/test.mp3' as string, nativePath: uni.env.CACHE_PATH + 'uni-audio/test/test.mp3' as string,
sdcardPath :'sdcard/uni-audio/test.mp3', sdcardPath: 'sdcard/uni-audio/test.mp3',
_audioContext: null as InnerAudioContext | null, _audioContext: null as InnerAudioContext | null,
supportPaths: [ supportPaths: [
{ {
...@@ -69,21 +69,35 @@ ...@@ -69,21 +69,35 @@
}); });
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try { fileManager.mkdir({
fileManager.rmdirSync(uni.env.CACHE_PATH+'uni-audio/test',true) dirPath: uni.env.CACHE_PATH + 'uni-audio/test',
} catch (e) { recursive: true,
success: (res) => {
fileManager.copyFile({
srcPath: '/static/test-audio/ForElise.mp3',
destPath: this.nativePath,
success: () => {
console.log("copy成功: ", res)
} }
})
try { },
fileManager.mkdirSync(uni.env.CACHE_PATH+'uni-audio/test',true) fail: (err) => {
} catch (e) { console.log("创建路径失败: ", err.errMsg)
if (err.errMsg.includes("file already exists")) {
console.log("已经包含该路径")
fileManager.copyFile({
srcPath: '/static/test-audio/ForElise.mp3',
destPath: this.nativePath,
success: (res) => {
console.log("copy成功: ", res)
},
fail: (err) => {
console.log("copy失败: ", err)
}
})
} }
try{
fileManager.copyFileSync(
'/static/test-audio/ForElise.mp3',
this.nativePath)
} catch(e){
} }
})
}, },
onUnload() { onUnload() {
...@@ -97,14 +111,14 @@ ...@@ -97,14 +111,14 @@
this._audioContext!.pause(); this._audioContext!.pause();
this.isPlaying = false; this.isPlaying = false;
}, },
play(audioUrl:string, index:number) { play(audioUrl : string, index : number) {
console.log(index,audioUrl); console.log(index, audioUrl);
if (this.isPlaying && this.playIndex == index) { if (this.isPlaying && this.playIndex == index) {
this.pause(); this.pause();
return; return;
} }
if(audioUrl == 'env'){ if (audioUrl == 'env') {
audioUrl=this.nativePath audioUrl = this.nativePath
} }
this.playIndex = index this.playIndex = index
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册