@aochuang/common 1.0.139 → 1.0.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/common/voice/voice.vue
CHANGED
|
@@ -81,25 +81,14 @@ export default {
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
created () {
|
|
84
|
-
const resolvePendingStart = () => {
|
|
85
|
-
if (this._pendingStartResolve) {
|
|
86
|
-
this._pendingStartResolve()
|
|
87
|
-
this._pendingStartResolve = null
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const releasePlayEndPromise = () => {
|
|
91
|
-
if (this.playEndPromise && this.playEndPromise.resolve) {
|
|
92
|
-
this.playEndPromise.resolve()
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
84
|
const newFactory = (Factory, options) => {
|
|
96
85
|
return new Factory(Object.assign({
|
|
97
86
|
playRate: this.playRate,
|
|
98
87
|
onError: (e) => {
|
|
99
88
|
this.starting = false
|
|
100
89
|
this.playStatus = 'stop'
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
this._resolvePendingStart()
|
|
91
|
+
this._releasePlayEndPromise()
|
|
103
92
|
this.$set(this.errorMsgMap, this.playId, e.message || '未知错误')
|
|
104
93
|
this.$emit('error', Object.assign({
|
|
105
94
|
playId: this.playId
|
|
@@ -178,9 +167,15 @@ export default {
|
|
|
178
167
|
start (id, val, total, cb) {
|
|
179
168
|
return new Promise((resolve) => {
|
|
180
169
|
this.stop()
|
|
170
|
+
const startToken = (this._startToken || 0) + 1
|
|
171
|
+
this._startToken = startToken
|
|
181
172
|
this._pendingStartResolve = resolve
|
|
182
173
|
const playEndPromise = this.playEndPromise || Promise.resolve()
|
|
183
174
|
playEndPromise.finally(() => {
|
|
175
|
+
if (this._startToken !== startToken) {
|
|
176
|
+
resolve()
|
|
177
|
+
return
|
|
178
|
+
}
|
|
184
179
|
this.playEndPromise = createPromise()
|
|
185
180
|
val = formatOssPath(val)
|
|
186
181
|
this.starting = true
|
|
@@ -189,12 +184,16 @@ export default {
|
|
|
189
184
|
this.$delete(this.errorMsgMap, id)
|
|
190
185
|
this.$nextTick(() => {
|
|
191
186
|
this.player.setUrl(val, (ctx) => {
|
|
187
|
+
if (this._startToken !== startToken) {
|
|
188
|
+
resolve()
|
|
189
|
+
return
|
|
190
|
+
}
|
|
192
191
|
cb && cb(ctx)
|
|
193
192
|
if (!ctx || ctx.status !== 'success') {
|
|
194
193
|
this.starting = false
|
|
195
194
|
this.playStatus = 'stop'
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
this._resolvePendingStart()
|
|
196
|
+
this._releasePlayEndPromise()
|
|
198
197
|
resolve()
|
|
199
198
|
return
|
|
200
199
|
}
|
|
@@ -203,7 +202,11 @@ export default {
|
|
|
203
202
|
Promise.all([
|
|
204
203
|
this.player.start()
|
|
205
204
|
]).finally(() => {
|
|
206
|
-
|
|
205
|
+
if (this._startToken !== startToken) {
|
|
206
|
+
resolve()
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
this._resolvePendingStart()
|
|
207
210
|
resolve()
|
|
208
211
|
})
|
|
209
212
|
})
|
|
@@ -225,14 +228,12 @@ export default {
|
|
|
225
228
|
this.player.resume()
|
|
226
229
|
},
|
|
227
230
|
stop () {
|
|
231
|
+
this._startToken = (this._startToken || 0) + 1
|
|
228
232
|
this.starting = false
|
|
229
233
|
this.playId = null
|
|
230
234
|
this.playStatus = 'stop'
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
this._pendingStartResolve = null
|
|
234
|
-
}
|
|
235
|
-
this.player.stop()
|
|
235
|
+
this._resolvePendingStart()
|
|
236
|
+
this.player && this.player.stop()
|
|
236
237
|
},
|
|
237
238
|
isPlaying (id) {
|
|
238
239
|
return this.playStatus === 'play' && this.playId === id
|
|
@@ -288,6 +289,17 @@ export default {
|
|
|
288
289
|
this.stop()
|
|
289
290
|
}
|
|
290
291
|
this.$delete(this.errorMsgMap, id)
|
|
292
|
+
},
|
|
293
|
+
_resolvePendingStart () {
|
|
294
|
+
if (this._pendingStartResolve) {
|
|
295
|
+
this._pendingStartResolve()
|
|
296
|
+
this._pendingStartResolve = null
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
_releasePlayEndPromise () {
|
|
300
|
+
if (this.playEndPromise && this.playEndPromise.resolve) {
|
|
301
|
+
this.playEndPromise.resolve()
|
|
302
|
+
}
|
|
291
303
|
}
|
|
292
304
|
},
|
|
293
305
|
render () {
|
|
@@ -287,6 +287,7 @@ export default {
|
|
|
287
287
|
},
|
|
288
288
|
playCurrPosition (val) {
|
|
289
289
|
this.controlPlayPosition = val
|
|
290
|
+
this.$emit('progress-change', val)
|
|
290
291
|
},
|
|
291
292
|
url () {
|
|
292
293
|
this.innerUrl = this.url
|
|
@@ -396,6 +397,57 @@ export default {
|
|
|
396
397
|
}
|
|
397
398
|
window.open(formatOssPath(this.voiceSrc), '_blank')
|
|
398
399
|
},
|
|
400
|
+
setPlayPosition (position) {
|
|
401
|
+
let targetValue = parseFloat(position)
|
|
402
|
+
if (!Number.isFinite(targetValue)) {
|
|
403
|
+
return
|
|
404
|
+
}
|
|
405
|
+
if (this.voiceSeconds) {
|
|
406
|
+
targetValue = Math.max(0, Math.min(targetValue, Number(this.voiceSeconds)))
|
|
407
|
+
}
|
|
408
|
+
clearTimeout(this._controlChangeTimer)
|
|
409
|
+
this.controlPlayPosition = targetValue
|
|
410
|
+
if (this.AcVoice.playUrl !== this.innerUrl) {
|
|
411
|
+
return Promise.all([
|
|
412
|
+
this.play()
|
|
413
|
+
]).then(() => {
|
|
414
|
+
if (!this.AcVoice.isSuperChangeProgress(this.innerUrl)) {
|
|
415
|
+
!this._notTips && this.$warn('AAC格式音频不支持更改播放进度,可以下载本地播放', () => {
|
|
416
|
+
this._notTips = false
|
|
417
|
+
})
|
|
418
|
+
this._notTips = true
|
|
419
|
+
return
|
|
420
|
+
}
|
|
421
|
+
this._controlChangeTimer = setTimeout(() => {
|
|
422
|
+
this.AcVoice.setPosition(targetValue)
|
|
423
|
+
}, 100)
|
|
424
|
+
})
|
|
425
|
+
} else {
|
|
426
|
+
if (!this.isPlaying) {
|
|
427
|
+
return this.play().then(() => {
|
|
428
|
+
if (!this.AcVoice.isSuperChangeProgress(this.innerUrl)) {
|
|
429
|
+
!this._notTips && this.$warn('AAC格式音频不支持更改播放进度,可以下载本地播放', () => {
|
|
430
|
+
this._notTips = false
|
|
431
|
+
})
|
|
432
|
+
this._notTips = true
|
|
433
|
+
return
|
|
434
|
+
}
|
|
435
|
+
this._controlChangeTimer = setTimeout(() => {
|
|
436
|
+
this.AcVoice.setPosition(targetValue)
|
|
437
|
+
}, 100)
|
|
438
|
+
})
|
|
439
|
+
} else {
|
|
440
|
+
if (!this.AcVoice.isSuperChangeProgress(this.innerUrl)) {
|
|
441
|
+
!this._notTips && this.$warn('AAC格式音频不支持更改播放进度,可以下载本地播放', () => {
|
|
442
|
+
this._notTips = false
|
|
443
|
+
})
|
|
444
|
+
this._notTips = true
|
|
445
|
+
return
|
|
446
|
+
}
|
|
447
|
+
this.AcVoice.setPosition(targetValue)
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
},
|
|
399
451
|
handleControlChange (evt) {
|
|
400
452
|
const targetValue = evt.target.value
|
|
401
453
|
clearTimeout(this._controlChangeTimer)
|