Commit 383d40df3cfbbddae3621bc2961d234396a1637f
1 parent
7498cb66
feat: add type for list & move failed from list
Showing
1 changed file
with
14 additions
and
8 deletions
pages/index/index.js
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | //获取应用实例 | 2 | //获取应用实例 |
3 | const app = getApp(); | 3 | const app = getApp(); |
4 | const selectedIndex = app.globalData.getSelectedTypeIndex(); | 4 | const selectedIndex = app.globalData.getSelectedTypeIndex(); |
5 | -const type = app.globalData.getTypeList(); | 5 | +const typeList = app.globalData.getTypeList(); |
6 | 6 | ||
7 | let audio = null; | 7 | let audio = null; |
8 | 8 | ||
@@ -10,7 +10,7 @@ Page({ | @@ -10,7 +10,7 @@ Page({ | ||
10 | data: { | 10 | data: { |
11 | placeholder: '点击此处输入文字', | 11 | placeholder: '点击此处输入文字', |
12 | text: '', | 12 | text: '', |
13 | - type, | 13 | + typeList, |
14 | selectedIndex: String(selectedIndex) ? selectedIndex : 5 | 14 | selectedIndex: String(selectedIndex) ? selectedIndex : 5 |
15 | }, | 15 | }, |
16 | onLoad(){ | 16 | onLoad(){ |
@@ -21,7 +21,10 @@ Page({ | @@ -21,7 +21,10 @@ Page({ | ||
21 | }, | 21 | }, |
22 | async play(){ | 22 | async play(){ |
23 | const text = this.data.text || this.data.placeholder; | 23 | const text = this.data.text || this.data.placeholder; |
24 | - const url = this.data.type[this.data.selectedIndex].createUrl(text); | 24 | + const selectedType = this.data.typeList[this.data.selectedIndex]; |
25 | + const url = selectedType.createUrl(text); | ||
26 | + const type = selectedType.desc; | ||
27 | + | ||
25 | wx.showLoading({ | 28 | wx.showLoading({ |
26 | title: '正在合成语音...', | 29 | title: '正在合成语音...', |
27 | mask: true | 30 | mask: true |
@@ -57,14 +60,15 @@ Page({ | @@ -57,14 +60,15 @@ Page({ | ||
57 | this.resetAudio(); | 60 | this.resetAudio(); |
58 | audio = wx.createInnerAudioContext({useWebAudioImplement: true}); | 61 | audio = wx.createInnerAudioContext({useWebAudioImplement: true}); |
59 | audio.autoplay = true; | 62 | audio.autoplay = true; |
60 | - // 播放失败要移除缓存内容 | ||
61 | - audio.onError((res) => { | ||
62 | - console.log(res.errMsg) | ||
63 | - console.log(res.errCode) | ||
64 | - }); | ||
65 | // 检查是否播放过 | 63 | // 检查是否播放过 |
66 | const audioList = app.globalData.getAudioList(); | 64 | const audioList = app.globalData.getAudioList(); |
67 | const played = audioList.find(v => v.url === url); | 65 | const played = audioList.find(v => v.url === url); |
66 | + // 播放失败要移除缓存内容 | ||
67 | + audio.onError(err => { | ||
68 | + if(err.errCode){ | ||
69 | + app.globalData.setAudioList('delete', played.path); | ||
70 | + } | ||
71 | + }); | ||
68 | // 播放过,使用本地文件减少请求,且从播放列表中移到最前 | 72 | // 播放过,使用本地文件减少请求,且从播放列表中移到最前 |
69 | if(played){ | 73 | if(played){ |
70 | app.globalData.setAudioList('delete', played.path); | 74 | app.globalData.setAudioList('delete', played.path); |
@@ -79,6 +83,8 @@ Page({ | @@ -79,6 +83,8 @@ Page({ | ||
79 | app.globalData.setAudioList('add', { | 83 | app.globalData.setAudioList('add', { |
80 | // 音频文本 | 84 | // 音频文本 |
81 | text, | 85 | text, |
86 | + // 音频音效 | ||
87 | + type, | ||
82 | // 音频网络地址 | 88 | // 音频网络地址 |
83 | url, | 89 | url, |
84 | // 音频本地地址 | 90 | // 音频本地地址 |