@aochuang/common 1.0.139 → 1.0.141

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.
@@ -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
- resolvePendingStart()
102
- releasePlayEndPromise()
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
- resolvePendingStart()
197
- releasePlayEndPromise()
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
- resolvePendingStart()
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
- if (this._pendingStartResolve) {
232
- this._pendingStartResolve()
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,69 @@ 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
+ const rawTargetValue = targetValue
406
+ if (this.voiceSeconds) {
407
+ targetValue = Math.max(0, Math.min(targetValue, Number(this.voiceSeconds)))
408
+ }
409
+ console.log('[vtt-sync] ac voice setPlayPosition', {
410
+ position,
411
+ rawTargetValue,
412
+ targetValue,
413
+ voiceSeconds: this.voiceSeconds,
414
+ controlPlayPosition: this.controlPlayPosition,
415
+ isPlaying: this.isPlaying,
416
+ isPause: this.isPause,
417
+ playUrl: this.AcVoice && this.AcVoice.playUrl,
418
+ innerUrl: this.innerUrl
419
+ })
420
+ clearTimeout(this._controlChangeTimer)
421
+ this.controlPlayPosition = targetValue
422
+ if (this.AcVoice.playUrl !== this.innerUrl) {
423
+ return Promise.all([
424
+ this.play()
425
+ ]).then(() => {
426
+ if (!this.AcVoice.isSuperChangeProgress(this.innerUrl)) {
427
+ !this._notTips && this.$warn('AAC格式音频不支持更改播放进度,可以下载本地播放', () => {
428
+ this._notTips = false
429
+ })
430
+ this._notTips = true
431
+ return
432
+ }
433
+ this._controlChangeTimer = setTimeout(() => {
434
+ this.AcVoice.setPosition(targetValue)
435
+ }, 100)
436
+ })
437
+ } else {
438
+ if (!this.isPlaying) {
439
+ return this.play().then(() => {
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._controlChangeTimer = setTimeout(() => {
448
+ this.AcVoice.setPosition(targetValue)
449
+ }, 100)
450
+ })
451
+ } else {
452
+ if (!this.AcVoice.isSuperChangeProgress(this.innerUrl)) {
453
+ !this._notTips && this.$warn('AAC格式音频不支持更改播放进度,可以下载本地播放', () => {
454
+ this._notTips = false
455
+ })
456
+ this._notTips = true
457
+ return
458
+ }
459
+ this.AcVoice.setPosition(targetValue)
460
+ }
461
+ }
462
+ },
399
463
  handleControlChange (evt) {
400
464
  const targetValue = evt.target.value
401
465
  clearTimeout(this._controlChangeTimer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/common",
3
- "version": "1.0.139",
3
+ "version": "1.0.141",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {