@94ai/nf-audio 3.3.65 → 3.3.66

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.
@@ -285,29 +285,36 @@ const _sfc_main = {
285
285
  return window.location.protocol === "https:" || window.location.hostname === "localhost";
286
286
  },
287
287
  async startAudioCtx() {
288
+ var _a, _b;
288
289
  if (this.isHighPrecision()) {
289
- if (!this.audioCtx) {
290
- this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
291
- this.audioSource = this.audioCtx.createMediaElementSource(this.audio);
292
- await this.audioCtx.audioWorklet.addModule("data:application/javascript," + encodeURIComponent(this.audioWorkletProcessor));
293
- this.processor = new AudioWorkletNode(this.audioCtx, "tick");
294
- this.audioSource.connect(this.processor).connect(this.audioCtx.destination);
295
- this.processor.port.onmessage = (event) => {
296
- if (event.data.command === "tick") {
297
- if (this.betweenPlaying) {
298
- if (this.betweenEnd) {
299
- if (this.debuglog) {
300
- console.log(this.audio.currentTime);
301
- }
302
- if (this.audio.currentTime >= this.betweenEnd) {
303
- this.pause();
290
+ try {
291
+ if (!this.audioCtx) {
292
+ this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
293
+ this.audioSource = this.audioCtx.createMediaElementSource(this.audio);
294
+ await ((_a = this.audioCtx.audioWorklet) == null ? void 0 : _a.addModule("data:application/javascript," + encodeURIComponent(this.audioWorkletProcessor)));
295
+ this.processor = new AudioWorkletNode(this.audioCtx, "tick");
296
+ this.audioSource.connect(this.processor).connect(this.audioCtx.destination);
297
+ if ((_b = this.processor) == null ? void 0 : _b.port) {
298
+ this.processor.port.onmessage = (event) => {
299
+ if (event.data.command === "tick") {
300
+ if (this.betweenPlaying) {
301
+ if (this.betweenEnd) {
302
+ if (this.debuglog) {
303
+ console.log(this.audio.currentTime);
304
+ }
305
+ if (this.audio.currentTime >= this.betweenEnd) {
306
+ this.pause();
307
+ }
308
+ }
304
309
  }
305
310
  }
306
- }
311
+ };
307
312
  }
308
- };
309
- } else {
310
- this.audioCtx.resume();
313
+ } else {
314
+ this.audioCtx.resume();
315
+ }
316
+ } catch (e) {
317
+ console.log(e);
311
318
  }
312
319
  this.processor.port.postMessage({
313
320
  command: "start"
@@ -333,10 +340,14 @@ const _sfc_main = {
333
340
  await this.startAudioCtx();
334
341
  this.audio.play();
335
342
  },
343
+ loadError(e) {
344
+ this.$emit("error", e);
345
+ },
336
346
  //视频在可以播放时触发
337
347
  getDuration() {
338
348
  this.totalTime = timeFormat(this.audio.duration);
339
349
  this.audio.volume = this.volume;
350
+ this.$emit("canPlay", this.totalTime);
340
351
  },
341
352
  //进度条发生变化时触发
342
353
  updateTime() {
@@ -543,6 +554,7 @@ var _sfc_render = function render() {
543
554
  },
544
555
  on: {
545
556
  "canplay": _vm.getDuration,
557
+ "error": _vm.loadError,
546
558
  "timeupdate": _vm.updateTime,
547
559
  "ended": _vm.handleAudioEnded
548
560
  }
@@ -283,29 +283,36 @@ const _sfc_main = {
283
283
  return window.location.protocol === "https:" || window.location.hostname === "localhost";
284
284
  },
285
285
  async startAudioCtx() {
286
+ var _a, _b;
286
287
  if (this.isHighPrecision()) {
287
- if (!this.audioCtx) {
288
- this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
289
- this.audioSource = this.audioCtx.createMediaElementSource(this.audio);
290
- await this.audioCtx.audioWorklet.addModule("data:application/javascript," + encodeURIComponent(this.audioWorkletProcessor));
291
- this.processor = new AudioWorkletNode(this.audioCtx, "tick");
292
- this.audioSource.connect(this.processor).connect(this.audioCtx.destination);
293
- this.processor.port.onmessage = (event) => {
294
- if (event.data.command === "tick") {
295
- if (this.betweenPlaying) {
296
- if (this.betweenEnd) {
297
- if (this.debuglog) {
298
- console.log(this.audio.currentTime);
299
- }
300
- if (this.audio.currentTime >= this.betweenEnd) {
301
- this.pause();
288
+ try {
289
+ if (!this.audioCtx) {
290
+ this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
291
+ this.audioSource = this.audioCtx.createMediaElementSource(this.audio);
292
+ await ((_a = this.audioCtx.audioWorklet) == null ? void 0 : _a.addModule("data:application/javascript," + encodeURIComponent(this.audioWorkletProcessor)));
293
+ this.processor = new AudioWorkletNode(this.audioCtx, "tick");
294
+ this.audioSource.connect(this.processor).connect(this.audioCtx.destination);
295
+ if ((_b = this.processor) == null ? void 0 : _b.port) {
296
+ this.processor.port.onmessage = (event) => {
297
+ if (event.data.command === "tick") {
298
+ if (this.betweenPlaying) {
299
+ if (this.betweenEnd) {
300
+ if (this.debuglog) {
301
+ console.log(this.audio.currentTime);
302
+ }
303
+ if (this.audio.currentTime >= this.betweenEnd) {
304
+ this.pause();
305
+ }
306
+ }
302
307
  }
303
308
  }
304
- }
309
+ };
305
310
  }
306
- };
307
- } else {
308
- this.audioCtx.resume();
311
+ } else {
312
+ this.audioCtx.resume();
313
+ }
314
+ } catch (e) {
315
+ console.log(e);
309
316
  }
310
317
  this.processor.port.postMessage({
311
318
  command: "start"
@@ -331,10 +338,14 @@ const _sfc_main = {
331
338
  await this.startAudioCtx();
332
339
  this.audio.play();
333
340
  },
341
+ loadError(e) {
342
+ this.$emit("error", e);
343
+ },
334
344
  //视频在可以播放时触发
335
345
  getDuration() {
336
346
  this.totalTime = timeFormat(this.audio.duration);
337
347
  this.audio.volume = this.volume;
348
+ this.$emit("canPlay", this.totalTime);
338
349
  },
339
350
  //进度条发生变化时触发
340
351
  updateTime() {
@@ -541,6 +552,7 @@ var _sfc_render = function render() {
541
552
  },
542
553
  on: {
543
554
  "canplay": _vm.getDuration,
555
+ "error": _vm.loadError,
544
556
  "timeupdate": _vm.updateTime,
545
557
  "ended": _vm.handleAudioEnded
546
558
  }
@@ -11,6 +11,7 @@
11
11
  :src="src"
12
12
  v-show="false"
13
13
  @canplay="getDuration"
14
+ @error="loadError"
14
15
  @timeupdate="updateTime"
15
16
  @ended="handleAudioEnded"
16
17
  />
@@ -450,28 +451,34 @@ export default {
450
451
  },
451
452
  async startAudioCtx() {
452
453
  if (this.isHighPrecision()) {
453
- if (!this.audioCtx) {
454
- this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
455
- this.audioSource = this.audioCtx.createMediaElementSource(this.audio);
456
- await this.audioCtx.audioWorklet.addModule('data:application/javascript,' + encodeURIComponent(this.audioWorkletProcessor));
457
- this.processor = new AudioWorkletNode(this.audioCtx, 'tick');
458
- this.audioSource.connect(this.processor).connect(this.audioCtx.destination);
459
- this.processor.port.onmessage = (event) => {
460
- if (event.data.command === 'tick') {
461
- if (this.betweenPlaying) {
462
- if (this.betweenEnd) {
463
- if (this.debuglog) {
464
- console.log(this.audio.currentTime)
465
- }
466
- if (this.audio.currentTime >= this.betweenEnd) {
467
- this.pause()
454
+ try {
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);
461
+ if (this.processor?.port) {
462
+ this.processor.port.onmessage = (event) => {
463
+ if (event.data.command === 'tick') {
464
+ if (this.betweenPlaying) {
465
+ if (this.betweenEnd) {
466
+ if (this.debuglog) {
467
+ console.log(this.audio.currentTime)
468
+ }
469
+ if (this.audio.currentTime >= this.betweenEnd) {
470
+ this.pause()
471
+ }
472
+ }
468
473
  }
469
474
  }
470
- }
475
+ };
471
476
  }
472
- };
473
- } else {
474
- this.audioCtx.resume()
477
+ } else {
478
+ this.audioCtx.resume()
479
+ }
480
+ } catch(e) {
481
+ console.log(e)
475
482
  }
476
483
  this.processor.port.postMessage({ command: 'start' });
477
484
  }
@@ -495,10 +502,14 @@ export default {
495
502
  await this.startAudioCtx()
496
503
  this.audio.play()
497
504
  },
505
+ loadError(e) {
506
+ this.$emit('error', e)
507
+ },
498
508
  //视频在可以播放时触发
499
509
  getDuration() {
500
510
  this.totalTime = timeFormat(this.audio.duration)
501
511
  this.audio.volume = this.volume
512
+ this.$emit('canPlay', this.totalTime)
502
513
  },
503
514
  //进度条发生变化时触发
504
515
  updateTime() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-audio",
3
- "version": "3.3.65",
3
+ "version": "3.3.66",
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.65",
17
+ "@94ai/nf-theme-chalk": "^3.3.66",
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": "925028777636d97723ff1e81517c48c1b6c00547"
33
+ "gitHead": "0b5045a8e003b4ddc7da70fc5d839120d6ccba94"
34
34
  }