@realsee/vreo 1.0.0-alpha.20 → 1.0.0-alpha.22

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/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # CHANGELOG
2
+ #1.0.0-alpha.21
3
+ - fix: 多段BgMusic播放问题
4
+
2
5
  #1.0.0-alpha.19
3
6
  - fix: 多段BgMusic可以重复播放
4
7
 
@@ -343,10 +343,17 @@ var Controller = /*#__PURE__*/function (_Subscribe) {
343
343
  _this$mediaInstance4,
344
344
  _this3 = this;
345
345
 
346
- if ((_this$mediaInstance = this.mediaInstance) !== null && _this$mediaInstance !== void 0 && _this$mediaInstance.ended) {
346
+ if ((_this$mediaInstance = this.mediaInstance) !== null && _this$mediaInstance !== void 0 && _this$mediaInstance.ended && this.mediaInstance.currentTime !== 0) {
347
+ var _this$vreoUnit;
348
+
349
+ if (this.ended) return;
350
+ (_this$vreoUnit = this.vreoUnit) === null || _this$vreoUnit === void 0 ? void 0 : _this$vreoUnit.keyframes.forEach(function (keyframe) {
351
+ return keyframe.parsed = false;
352
+ });
347
353
  this.setEnded(true);
348
354
  this.setPlaying(false);
349
355
  this.mediaInstance.pause();
356
+ this.mediaInstance.currentTime = 0;
350
357
  return;
351
358
  }
352
359
 
@@ -391,28 +398,25 @@ var Controller = /*#__PURE__*/function (_Subscribe) {
391
398
  }, {
392
399
  key: "dispose",
393
400
  value: function dispose() {
394
- this.setPlaying(false);
401
+ var _this$vreoUnit2, _this$stopInterval;
395
402
 
396
- if (this.currentKeyframes) {
397
- this.currentKeyframes.forEach(function (keyframe) {
398
- return keyframe.parsed = false;
399
- });
400
- }
403
+ this.setPlaying(false);
404
+ (_this$vreoUnit2 = this.vreoUnit) === null || _this$vreoUnit2 === void 0 ? void 0 : _this$vreoUnit2.keyframes.forEach(function (keyframe) {
405
+ return keyframe.parsed = false;
406
+ });
401
407
  /**
402
408
  * 清理掉数据
403
409
  */
404
410
 
405
-
406
411
  this.vreoUnit = undefined;
407
412
 
408
413
  if (this.mediaInstance) {
414
+ this.mediaInstance.pause();
409
415
  this.mediaInstance.currentTime = 0;
410
416
  }
411
417
 
412
- if (this.stopInterval) {
413
- this.stopInterval();
414
- this.stopInterval = undefined;
415
- }
418
+ (_this$stopInterval = this.stopInterval) === null || _this$stopInterval === void 0 ? void 0 : _this$stopInterval.call(this);
419
+ this.stopInterval = undefined;
416
420
  }
417
421
  }]);
418
422
 
@@ -289,6 +289,7 @@ var Player = /*#__PURE__*/function (_Subscribe) {
289
289
  Object.assign(window, {
290
290
  $vreoController: this.controller
291
291
  });
292
+ this.controller.setEnded(false);
292
293
  this.controller.setPlaying(true);
293
294
  return true;
294
295
  }
@@ -17,25 +17,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
17
17
 
18
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
19
 
20
- var audioList = [];
20
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
+
22
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
21
23
 
22
24
  function getAudio() {
23
25
  var src = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
24
26
  var currentTime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
25
-
26
- var audio = function () {
27
- var audio = audioList.find(function (audio) {
28
- return audio.src === src && audio.paused;
29
- });
30
- if (audio) return audio;else {
31
- var newAudio = new Audio(src);
32
- audioList.push(newAudio);
33
- return newAudio;
34
- }
35
- }();
36
-
27
+ var audio = new Audio();
28
+ audio.src = src;
37
29
  audio.currentTime = currentTime;
38
- audio.setAttribute('playsinline', 'true');
39
30
  return audio;
40
31
  }
41
32
 
@@ -49,40 +40,55 @@ function BgMusic() {
49
40
  }
50
41
  }, []);
51
42
  React.useEffect(function () {
52
- var callback = function callback(keyframe, currentTime) {
53
- console.log({
54
- currentTime: currentTime
55
- });
56
- var start = keyframe.start,
57
- end = keyframe.end;
58
- var audio = getAudio(keyframe.data.url, Math.max(currentTime - start, 0));
59
-
60
- var playCallback = function playCallback() {
61
- audio.play();
62
- };
63
-
64
- audio.addEventListener('canplaythrough', playCallback);
65
- cleanTimeout();
66
-
67
- var cleanAudio = function cleanAudio() {
68
- console.log('cleanAudio', keyframe.start);
69
- audio.removeEventListener('canplaythrough', playCallback);
70
- audio.pause();
71
- cleanTimeout();
43
+ var callback = /*#__PURE__*/function () {
44
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(keyframe, currentTime) {
45
+ var start, end, audio, playCallback, cleanAudio, duration;
46
+ return regeneratorRuntime.wrap(function _callee$(_context) {
47
+ while (1) {
48
+ switch (_context.prev = _context.next) {
49
+ case 0:
50
+ start = keyframe.start, end = keyframe.end;
51
+ audio = getAudio(keyframe.data.url, Math.max((currentTime - start) / 1000, 0));
52
+
53
+ playCallback = function playCallback() {
54
+ audio.play();
55
+ };
56
+
57
+ audio.addEventListener('canplaythrough', playCallback);
58
+ cleanTimeout();
59
+
60
+ cleanAudio = function cleanAudio() {
61
+ audio.removeEventListener('canplaythrough', playCallback);
62
+ audio.pause();
63
+ cleanTimeout();
64
+ };
65
+
66
+ duration = end - start;
67
+ audio.addEventListener('ended', cleanAudio); // 音频加载会有时间,所以不通过这种方式停止,而是等播完停止
68
+ // timeoutIdRef.current = setTimeout(() => {
69
+ // cleanAudio()
70
+ // }, duration)
71
+
72
+ controller.once('paused', function () {
73
+ cleanAudio();
74
+ });
75
+
76
+ case 9:
77
+ case "end":
78
+ return _context.stop();
79
+ }
80
+ }
81
+ }, _callee);
82
+ }));
83
+
84
+ return function callback(_x, _x2) {
85
+ return _ref.apply(this, arguments);
72
86
  };
73
-
74
- var duration = end - start;
75
- timeoutIdRef.current = setTimeout(function () {
76
- console.log('timeout', duration);
77
- cleanAudio();
78
- }, duration);
79
- controller.once('paused', function () {
80
- cleanAudio();
81
- });
82
- };
87
+ }();
83
88
 
84
89
  controller.on(_VreoUnit.VreoKeyframeEnum.BgMusic, callback);
85
90
  return function () {
91
+ console.log('off');
86
92
  controller.off(_VreoUnit.VreoKeyframeEnum.BgMusic, callback);
87
93
  cleanTimeout();
88
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realsee/vreo",
3
- "version": "1.0.0-alpha.20",
3
+ "version": "1.0.0-alpha.22",
4
4
  "description": "Vreo (VR Video 缩写) 是基于如视三维渲染引擎 Five 和 用户界面构建库 React 实现的如视 3D 空间剧本播放器。",
5
5
  "keywords": [
6
6
  "realsee",