@94ai/nf-audio 3.3.67 → 3.3.69

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.
@@ -35,7 +35,7 @@ const _sfc_main = {
35
35
  },
36
36
  unloadTip: {
37
37
  type: String,
38
- default: "音频还未加载完成"
38
+ default: "音频资源暂无法播放"
39
39
  },
40
40
  disabled: {
41
41
  type: Boolean,
@@ -373,7 +373,7 @@ const _sfc_main = {
373
373
  },
374
374
  betweenPlay() {
375
375
  if (!this.disabled) {
376
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
376
+ if (this.checkAudioEffectNull()) {
377
377
  nfMessage.Message.warning(this.unloadTip);
378
378
  this.paused = true;
379
379
  this.betweenPlaying = false;
@@ -388,10 +388,19 @@ 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 || Number.isNaN(this.audio.duration)) {
403
+ if (this.checkAudioEffectNull()) {
395
404
  if (!this.paused) {
396
405
  nfMessage.Message.warning(this.unloadTip);
397
406
  }
@@ -399,8 +408,8 @@ const _sfc_main = {
399
408
  this.betweenPlaying = false;
400
409
  return false;
401
410
  }
402
- this.updateProgress(e.offsetX);
403
- this.$emit("updateProgress", e.offsetX);
411
+ this.updateProgress(this.getOffsetX(e));
412
+ this.$emit("updateProgress", this.getOffsetX(e));
404
413
  }
405
414
  },
406
415
  //更新进度
@@ -413,7 +422,7 @@ const _sfc_main = {
413
422
  //鼠标弹起
414
423
  handleMouseup() {
415
424
  if (!this.disabled) {
416
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
425
+ if (this.checkAudioEffectNull()) {
417
426
  nfMessage.Message.warning(this.unloadTip);
418
427
  this.paused = true;
419
428
  this.betweenPlaying = false;
@@ -434,12 +443,15 @@ const _sfc_main = {
434
443
  //调整进度
435
444
  handleMousedown() {
436
445
  if (!this.disabled) {
446
+ if (this.checkAudioEffectNull()) {
447
+ return;
448
+ }
437
449
  this.pauseAudio();
438
450
  this.paused = true;
439
451
  this.betweenPlaying = false;
440
452
  const progressContainer = this.$refs.progressContainer;
441
- this.moveMin = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft;
442
- this.moveMax = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft + progressContainer.clientWidth;
453
+ this.moveMin = progressContainer.getBoundingClientRect().left;
454
+ this.moveMax = progressContainer.getBoundingClientRect().left + progressContainer.clientWidth;
443
455
  this.progressBarWidth = this.$refs.progressBar.clientWidth / 2;
444
456
  document.addEventListener("mousemove", this.moveX);
445
457
  document.addEventListener("mouseup", () => {
@@ -472,10 +484,13 @@ const _sfc_main = {
472
484
  this.$refs.progressBar.style.left = MoveX - this.$refs.progressBar.clientWidth / 2 + "px";
473
485
  }
474
486
  },
487
+ checkAudioEffectNull() {
488
+ return this.audio.duration === 0 || Number.isNaN(this.audio.duration);
489
+ },
475
490
  jumpToTime(time) {
476
491
  if (!this.disabled) {
477
492
  this.pauseAudio();
478
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
493
+ if (this.checkAudioEffectNull()) {
479
494
  nfMessage.Message.warning(this.unloadTip);
480
495
  this.paused = true;
481
496
  this.betweenPlaying = false;
@@ -33,7 +33,7 @@ const _sfc_main = {
33
33
  },
34
34
  unloadTip: {
35
35
  type: String,
36
- default: "音频还未加载完成"
36
+ default: "音频资源暂无法播放"
37
37
  },
38
38
  disabled: {
39
39
  type: Boolean,
@@ -371,7 +371,7 @@ const _sfc_main = {
371
371
  },
372
372
  betweenPlay() {
373
373
  if (!this.disabled) {
374
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
374
+ if (this.checkAudioEffectNull()) {
375
375
  Message.warning(this.unloadTip);
376
376
  this.paused = true;
377
377
  this.betweenPlaying = false;
@@ -386,10 +386,19 @@ 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 || Number.isNaN(this.audio.duration)) {
401
+ if (this.checkAudioEffectNull()) {
393
402
  if (!this.paused) {
394
403
  Message.warning(this.unloadTip);
395
404
  }
@@ -397,8 +406,8 @@ const _sfc_main = {
397
406
  this.betweenPlaying = false;
398
407
  return false;
399
408
  }
400
- this.updateProgress(e.offsetX);
401
- this.$emit("updateProgress", e.offsetX);
409
+ this.updateProgress(this.getOffsetX(e));
410
+ this.$emit("updateProgress", this.getOffsetX(e));
402
411
  }
403
412
  },
404
413
  //更新进度
@@ -411,7 +420,7 @@ const _sfc_main = {
411
420
  //鼠标弹起
412
421
  handleMouseup() {
413
422
  if (!this.disabled) {
414
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
423
+ if (this.checkAudioEffectNull()) {
415
424
  Message.warning(this.unloadTip);
416
425
  this.paused = true;
417
426
  this.betweenPlaying = false;
@@ -432,12 +441,15 @@ const _sfc_main = {
432
441
  //调整进度
433
442
  handleMousedown() {
434
443
  if (!this.disabled) {
444
+ if (this.checkAudioEffectNull()) {
445
+ return;
446
+ }
435
447
  this.pauseAudio();
436
448
  this.paused = true;
437
449
  this.betweenPlaying = false;
438
450
  const progressContainer = this.$refs.progressContainer;
439
- this.moveMin = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft;
440
- this.moveMax = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft + progressContainer.clientWidth;
451
+ this.moveMin = progressContainer.getBoundingClientRect().left;
452
+ this.moveMax = progressContainer.getBoundingClientRect().left + progressContainer.clientWidth;
441
453
  this.progressBarWidth = this.$refs.progressBar.clientWidth / 2;
442
454
  document.addEventListener("mousemove", this.moveX);
443
455
  document.addEventListener("mouseup", () => {
@@ -470,10 +482,13 @@ const _sfc_main = {
470
482
  this.$refs.progressBar.style.left = MoveX - this.$refs.progressBar.clientWidth / 2 + "px";
471
483
  }
472
484
  },
485
+ checkAudioEffectNull() {
486
+ return this.audio.duration === 0 || Number.isNaN(this.audio.duration);
487
+ },
473
488
  jumpToTime(time) {
474
489
  if (!this.disabled) {
475
490
  this.pauseAudio();
476
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
491
+ if (this.checkAudioEffectNull()) {
477
492
  Message.warning(this.unloadTip);
478
493
  this.paused = true;
479
494
  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,
@@ -193,7 +193,7 @@ export default {
193
193
  },
194
194
  unloadTip: {
195
195
  type: String,
196
- default: '音频还未加载完成'
196
+ default: '音频资源暂无法播放'
197
197
  },
198
198
  disabled: {
199
199
  type: Boolean,
@@ -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 || Number.isNaN(this.audio.duration)) {
540
+ if (this.checkAudioEffectNull()) {
541
541
  Message.warning(this.unloadTip)
542
542
  this.paused = true
543
543
  this.betweenPlaying = false
@@ -552,10 +552,19 @@ 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 || Number.isNaN(this.audio.duration)) {
567
+ if (this.checkAudioEffectNull()) {
559
568
  if (!this.paused) {
560
569
  Message.warning(this.unloadTip)
561
570
  }
@@ -563,8 +572,8 @@ export default {
563
572
  this.betweenPlaying = false
564
573
  return false
565
574
  }
566
- this.updateProgress(e.offsetX)
567
- this.$emit('updateProgress', e.offsetX)
575
+ this.updateProgress(this.getOffsetX(e))
576
+ this.$emit('updateProgress', this.getOffsetX(e))
568
577
  }
569
578
  },
570
579
  //更新进度
@@ -580,7 +589,7 @@ export default {
580
589
  //鼠标弹起
581
590
  handleMouseup() {
582
591
  if (!this.disabled) {
583
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
592
+ if (this.checkAudioEffectNull()) {
584
593
  Message.warning(this.unloadTip)
585
594
  this.paused = true
586
595
  this.betweenPlaying = false
@@ -601,14 +610,17 @@ export default {
601
610
  //调整进度
602
611
  handleMousedown() {
603
612
  if (!this.disabled) {
613
+ if (this.checkAudioEffectNull()) {
614
+ return
615
+ }
604
616
  this.pauseAudio()
605
617
  this.paused = true
606
618
  this.betweenPlaying = false
607
619
  const progressContainer = this.$refs.progressContainer
608
620
  //进度条 左 边距离页面左边的距离 移动最小值
609
- this.moveMin = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft
621
+ this.moveMin = progressContainer.getBoundingClientRect().left
610
622
  //进度条 右 边距离页面左边的距离 移动最大值
611
- this.moveMax = progressContainer.offsetParent.offsetLeft + progressContainer.offsetLeft + progressContainer.clientWidth
623
+ this.moveMax = progressContainer.getBoundingClientRect().left + progressContainer.clientWidth
612
624
  //progressBar的宽度
613
625
  this.progressBarWidth = (this.$refs.progressBar.clientWidth / 2)
614
626
  //获取当前鼠标的位置 X
@@ -646,10 +658,13 @@ export default {
646
658
  this.$refs.progressBar.style.left = MoveX - (this.$refs.progressBar.clientWidth / 2) + 'px'
647
659
  }
648
660
  },
661
+ checkAudioEffectNull() {
662
+ return this.audio.duration === 0 || Number.isNaN(this.audio.duration)
663
+ },
649
664
  jumpToTime(time) {
650
665
  if (!this.disabled) {
651
666
  this.pauseAudio()
652
- if (this.audio.duration === 0 || Number.isNaN(this.audio.duration)) {
667
+ if (this.checkAudioEffectNull()) {
653
668
  Message.warning(this.unloadTip)
654
669
  this.paused = true
655
670
  this.betweenPlaying = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-audio",
3
- "version": "3.3.67",
3
+ "version": "3.3.69",
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.67",
17
+ "@94ai/nf-theme-chalk": "^3.3.69",
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": "2c752dc6246ba8252562937829c091ae21cca8f2"
33
+ "gitHead": "e681a4e9428cd1c1d6ce91e4cf863c4cea49c7d2"
34
34
  }