@94ai/nf-audio 3.3.66 → 3.3.68

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.
@@ -373,7 +373,7 @@ const _sfc_main = {
373
373
  },
374
374
  betweenPlay() {
375
375
  if (!this.disabled) {
376
- if (this.audio.duration === 0) {
376
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
377
377
  nfMessage.Message.warning(this.unloadTip);
378
378
  this.paused = true;
379
379
  this.betweenPlaying = false;
@@ -388,17 +388,28 @@ const _sfc_main = {
388
388
  this.$refs.progressBar.style.left = this.$refs.progressContainer.clientWidth - this.$refs.progressBar.clientWidth / 2 + "px";
389
389
  this.pause();
390
390
  },
391
+ getOffsetX(ev) {
392
+ const e = ev || window.event;
393
+ const srcObj = e.target || e.srcElement;
394
+ if (e.offsetX) {
395
+ return e.offsetX;
396
+ }
397
+ const rect = srcObj.getBoundingClientRect();
398
+ return e.clientX - rect.left;
399
+ },
391
400
  //点击进度条更新进度
392
401
  clickProgress(e) {
393
402
  if (!this.disabled) {
394
- if (this.audio.duration === 0) {
395
- nfMessage.Message.warning(this.unloadTip);
403
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
404
+ if (!this.paused) {
405
+ nfMessage.Message.warning(this.unloadTip);
406
+ }
396
407
  this.paused = true;
397
408
  this.betweenPlaying = false;
398
409
  return false;
399
410
  }
400
- this.updateProgress(e.offsetX);
401
- this.$emit("updateProgress", e.offsetX);
411
+ this.updateProgress(this.getOffsetX(e));
412
+ this.$emit("updateProgress", this.getOffsetX(e));
402
413
  }
403
414
  },
404
415
  //更新进度
@@ -411,7 +422,7 @@ const _sfc_main = {
411
422
  //鼠标弹起
412
423
  handleMouseup() {
413
424
  if (!this.disabled) {
414
- if (this.audio.duration === 0) {
425
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
415
426
  nfMessage.Message.warning(this.unloadTip);
416
427
  this.paused = true;
417
428
  this.betweenPlaying = false;
@@ -436,8 +447,8 @@ const _sfc_main = {
436
447
  this.paused = true;
437
448
  this.betweenPlaying = false;
438
449
  const progressContainer = this.$refs.progressContainer;
439
- this.moveMin = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft;
440
- this.moveMax = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft + progressContainer.clientWidth;
450
+ this.moveMin = progressContainer.getBoundingClientRect().left;
451
+ this.moveMax = progressContainer.getBoundingClientRect().left + progressContainer.clientWidth;
441
452
  this.progressBarWidth = this.$refs.progressBar.clientWidth / 2;
442
453
  document.addEventListener("mousemove", this.moveX);
443
454
  document.addEventListener("mouseup", () => {
@@ -473,7 +484,7 @@ const _sfc_main = {
473
484
  jumpToTime(time) {
474
485
  if (!this.disabled) {
475
486
  this.pauseAudio();
476
- if (this.audio.duration === 0) {
487
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
477
488
  nfMessage.Message.warning(this.unloadTip);
478
489
  this.paused = true;
479
490
  this.betweenPlaying = false;
@@ -371,7 +371,7 @@ const _sfc_main = {
371
371
  },
372
372
  betweenPlay() {
373
373
  if (!this.disabled) {
374
- if (this.audio.duration === 0) {
374
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
375
375
  Message.warning(this.unloadTip);
376
376
  this.paused = true;
377
377
  this.betweenPlaying = false;
@@ -386,17 +386,28 @@ const _sfc_main = {
386
386
  this.$refs.progressBar.style.left = this.$refs.progressContainer.clientWidth - this.$refs.progressBar.clientWidth / 2 + "px";
387
387
  this.pause();
388
388
  },
389
+ getOffsetX(ev) {
390
+ const e = ev || window.event;
391
+ const srcObj = e.target || e.srcElement;
392
+ if (e.offsetX) {
393
+ return e.offsetX;
394
+ }
395
+ const rect = srcObj.getBoundingClientRect();
396
+ return e.clientX - rect.left;
397
+ },
389
398
  //点击进度条更新进度
390
399
  clickProgress(e) {
391
400
  if (!this.disabled) {
392
- if (this.audio.duration === 0) {
393
- Message.warning(this.unloadTip);
401
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
402
+ if (!this.paused) {
403
+ Message.warning(this.unloadTip);
404
+ }
394
405
  this.paused = true;
395
406
  this.betweenPlaying = false;
396
407
  return false;
397
408
  }
398
- this.updateProgress(e.offsetX);
399
- this.$emit("updateProgress", e.offsetX);
409
+ this.updateProgress(this.getOffsetX(e));
410
+ this.$emit("updateProgress", this.getOffsetX(e));
400
411
  }
401
412
  },
402
413
  //更新进度
@@ -409,7 +420,7 @@ const _sfc_main = {
409
420
  //鼠标弹起
410
421
  handleMouseup() {
411
422
  if (!this.disabled) {
412
- if (this.audio.duration === 0) {
423
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
413
424
  Message.warning(this.unloadTip);
414
425
  this.paused = true;
415
426
  this.betweenPlaying = false;
@@ -434,8 +445,8 @@ const _sfc_main = {
434
445
  this.paused = true;
435
446
  this.betweenPlaying = false;
436
447
  const progressContainer = this.$refs.progressContainer;
437
- this.moveMin = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft;
438
- this.moveMax = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft + progressContainer.clientWidth;
448
+ this.moveMin = progressContainer.getBoundingClientRect().left;
449
+ this.moveMax = progressContainer.getBoundingClientRect().left + progressContainer.clientWidth;
439
450
  this.progressBarWidth = this.$refs.progressBar.clientWidth / 2;
440
451
  document.addEventListener("mousemove", this.moveX);
441
452
  document.addEventListener("mouseup", () => {
@@ -471,7 +482,7 @@ const _sfc_main = {
471
482
  jumpToTime(time) {
472
483
  if (!this.disabled) {
473
484
  this.pauseAudio();
474
- if (this.audio.duration === 0) {
485
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
475
486
  Message.warning(this.unloadTip);
476
487
  this.paused = true;
477
488
  this.betweenPlaying = false;
@@ -43,7 +43,7 @@
43
43
  </slot>
44
44
 
45
45
  <!-- 快退-->
46
- <slot name="fastBack" v-if="backSecond" >
46
+ <slot name="fastBack" v-if="backSecond">
47
47
  <el-tooltip class="nf-audio-pre"
48
48
  placement="top"
49
49
  :disabled="disabled"
@@ -173,7 +173,7 @@ export default {
173
173
  default: false
174
174
  },
175
175
  size: {
176
- type: String,
176
+ type: String
177
177
  },
178
178
  speedDesc: {
179
179
  type: String,
@@ -341,7 +341,7 @@ export default {
341
341
  try {
342
342
  this.audioCtx?.close()
343
343
  } catch (e) {
344
- //
344
+ //
345
345
  } finally {
346
346
  this.audioCtx = undefined
347
347
  }
@@ -415,7 +415,7 @@ export default {
415
415
  if (!this.disabled) {
416
416
  if (this.audio.readyState >= 2) {
417
417
  // 如果音频资源已加载元数据或更多,可以播放
418
- if(this.audio.paused) {
418
+ if (this.audio.paused) {
419
419
  this.playAudio()
420
420
  } else {
421
421
  this.pauseAudio()
@@ -433,7 +433,7 @@ export default {
433
433
  },
434
434
  suspendAudioCtx() {
435
435
  try {
436
- this.processor?.port?.postMessage({ command: 'end' });
436
+ this.processor?.port?.postMessage({ command: 'end' })
437
437
  } catch (e) {
438
438
  //
439
439
  }
@@ -453,11 +453,11 @@ export default {
453
453
  if (this.isHighPrecision()) {
454
454
  try {
455
455
  if (!this.audioCtx) {
456
- this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
457
- this.audioSource = this.audioCtx.createMediaElementSource(this.audio);
458
- await this.audioCtx.audioWorklet?.addModule('data:application/javascript,' + encodeURIComponent(this.audioWorkletProcessor));
459
- this.processor = new AudioWorkletNode(this.audioCtx, 'tick');
460
- this.audioSource.connect(this.processor).connect(this.audioCtx.destination);
456
+ this.audioCtx = new (window.AudioContext || window.webkitAudioContext)()
457
+ this.audioSource = this.audioCtx.createMediaElementSource(this.audio)
458
+ await this.audioCtx.audioWorklet?.addModule('data:application/javascript,' + encodeURIComponent(this.audioWorkletProcessor))
459
+ this.processor = new AudioWorkletNode(this.audioCtx, 'tick')
460
+ this.audioSource.connect(this.processor).connect(this.audioCtx.destination)
461
461
  if (this.processor?.port) {
462
462
  this.processor.port.onmessage = (event) => {
463
463
  if (event.data.command === 'tick') {
@@ -472,15 +472,15 @@ export default {
472
472
  }
473
473
  }
474
474
  }
475
- };
475
+ }
476
476
  }
477
477
  } else {
478
478
  this.audioCtx.resume()
479
479
  }
480
- } catch(e) {
480
+ } catch (e) {
481
481
  console.log(e)
482
482
  }
483
- this.processor.port.postMessage({ command: 'start' });
483
+ this.processor.port.postMessage({ command: 'start' })
484
484
  }
485
485
  },
486
486
  pause() {
@@ -537,7 +537,7 @@ export default {
537
537
  },
538
538
  betweenPlay() {
539
539
  if (!this.disabled) {
540
- if (this.audio.duration === 0) {
540
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
541
541
  Message.warning(this.unloadTip)
542
542
  this.paused = true
543
543
  this.betweenPlaying = false
@@ -552,17 +552,28 @@ export default {
552
552
  this.$refs.progressBar.style.left = this.$refs.progressContainer.clientWidth - (this.$refs.progressBar.clientWidth / 2) + 'px'
553
553
  this.pause()
554
554
  },
555
+ getOffsetX(ev) {
556
+ const e = ev || window.event
557
+ const srcObj = e.target || e.srcElement
558
+ if (e.offsetX) {
559
+ return e.offsetX
560
+ }
561
+ const rect = srcObj.getBoundingClientRect()
562
+ return e.clientX - rect.left
563
+ },
555
564
  //点击进度条更新进度
556
565
  clickProgress(e) {
557
566
  if (!this.disabled) {
558
- if (this.audio.duration === 0) {
559
- Message.warning(this.unloadTip)
567
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
568
+ if (!this.paused) {
569
+ Message.warning(this.unloadTip)
570
+ }
560
571
  this.paused = true
561
572
  this.betweenPlaying = false
562
573
  return false
563
574
  }
564
- this.updateProgress(e.offsetX)
565
- this.$emit('updateProgress', e.offsetX)
575
+ this.updateProgress(this.getOffsetX(e))
576
+ this.$emit('updateProgress', this.getOffsetX(e))
566
577
  }
567
578
  },
568
579
  //更新进度
@@ -578,7 +589,7 @@ export default {
578
589
  //鼠标弹起
579
590
  handleMouseup() {
580
591
  if (!this.disabled) {
581
- if (this.audio.duration === 0) {
592
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
582
593
  Message.warning(this.unloadTip)
583
594
  this.paused = true
584
595
  this.betweenPlaying = false
@@ -604,9 +615,9 @@ export default {
604
615
  this.betweenPlaying = false
605
616
  const progressContainer = this.$refs.progressContainer
606
617
  //进度条 左 边距离页面左边的距离 移动最小值
607
- this.moveMin = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft
618
+ this.moveMin = progressContainer.getBoundingClientRect().left
608
619
  //进度条 右 边距离页面左边的距离 移动最大值
609
- this.moveMax = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft + progressContainer.clientWidth
620
+ this.moveMax = progressContainer.getBoundingClientRect().left + progressContainer.clientWidth
610
621
  //progressBar的宽度
611
622
  this.progressBarWidth = (this.$refs.progressBar.clientWidth / 2)
612
623
  //获取当前鼠标的位置 X
@@ -647,7 +658,7 @@ export default {
647
658
  jumpToTime(time) {
648
659
  if (!this.disabled) {
649
660
  this.pauseAudio()
650
- if (this.audio.duration === 0) {
661
+ if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
651
662
  Message.warning(this.unloadTip)
652
663
  this.paused = true
653
664
  this.betweenPlaying = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-audio",
3
- "version": "3.3.66",
3
+ "version": "3.3.68",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "liuxiangxiang <liuxiangxiang@94ai.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^3.3.66",
17
+ "@94ai/nf-theme-chalk": "^3.3.68",
18
18
  "vue-demi": "^0.14.5"
19
19
  },
20
20
  "peerDependenciesMeta": {
@@ -30,5 +30,5 @@
30
30
  "types": "lib/index.d.ts",
31
31
  "main": "lib/nf-audio.cjs.js",
32
32
  "module": "lib/nf-audio.esm-bundler.js",
33
- "gitHead": "0b5045a8e003b4ddc7da70fc5d839120d6ccba94"
33
+ "gitHead": "2c752dc6246ba8252562937829c091ae21cca8f2"
34
34
  }