@realsee/vreo 1.0.0-alpha.27 → 1.0.0-alpha.29
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/lib/Player/Controller.js
CHANGED
|
@@ -263,7 +263,12 @@ var Controller = /*#__PURE__*/function (_Subscribe) {
|
|
|
263
263
|
// 没有被解析过且开始时间低于当前时间戳 100ms
|
|
264
264
|
return keyframes.filter(function (keyframe) {
|
|
265
265
|
if (keyframe.parsed) return false;
|
|
266
|
+
// 检测结束时间
|
|
267
|
+
if (keyframe.end < _this2.currentTime) return false;
|
|
268
|
+
// 检测开始时间
|
|
269
|
+
if (keyframe.start > _this2.currentTime) return false;
|
|
266
270
|
if (keyframe.type === _VreoUnit.VreoKeyframeEnum.BgMusic) return true;
|
|
271
|
+
// 开始时间低于当前时间戳 100ms
|
|
267
272
|
var dur = _this2.currentTime - keyframe.start;
|
|
268
273
|
return dur <= 100 && dur >= 0;
|
|
269
274
|
});
|
|
@@ -23,22 +23,29 @@ function BgMusic() {
|
|
|
23
23
|
React.useEffect(function () {
|
|
24
24
|
var callback = /*#__PURE__*/function () {
|
|
25
25
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(keyframe, currentTime) {
|
|
26
|
-
var start, end, audio, cleanAudio;
|
|
26
|
+
var start, end, _currentTime, audio, cleanAudio;
|
|
27
27
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
28
28
|
while (1) {
|
|
29
29
|
switch (_context.prev = _context.next) {
|
|
30
30
|
case 0:
|
|
31
31
|
start = keyframe.start, end = keyframe.end;
|
|
32
|
+
_currentTime = (currentTime - start) / 1000;
|
|
33
|
+
if (!(_currentTime < 0 || _currentTime >= keyframe.end - keyframe.start)) {
|
|
34
|
+
_context.next = 4;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return _context.abrupt("return");
|
|
38
|
+
case 4:
|
|
32
39
|
audio = (0, _Audio.getAudio)(keyframe.data.url);
|
|
33
|
-
audio.currentTime = Math.max(
|
|
40
|
+
audio.currentTime = Math.max(0, _currentTime);
|
|
34
41
|
console.log('play', audio.src);
|
|
35
42
|
// const play = () => audio.play()
|
|
36
43
|
|
|
37
44
|
audio.play();
|
|
38
45
|
cleanAudio = function cleanAudio() {
|
|
39
|
-
console.log('clean audio');
|
|
40
46
|
// audio.removeEventListener('canplaythrough', play)
|
|
41
47
|
audio.pause();
|
|
48
|
+
audio.src = '';
|
|
42
49
|
// cleanTimeout()
|
|
43
50
|
}; // audio.addEventListener('canplaythrough', play)
|
|
44
51
|
|
|
@@ -48,7 +55,7 @@ function BgMusic() {
|
|
|
48
55
|
controller.once('paused', function () {
|
|
49
56
|
cleanAudio();
|
|
50
57
|
});
|
|
51
|
-
case
|
|
58
|
+
case 11:
|
|
52
59
|
case "end":
|
|
53
60
|
return _context.stop();
|
|
54
61
|
}
|
|
@@ -40,13 +40,12 @@ function getAudio(src) {
|
|
|
40
40
|
return !audio.realSrc || audio.realSrc === blankAudioSrc;
|
|
41
41
|
});
|
|
42
42
|
if (!audio) {
|
|
43
|
-
console.warn('未找到缓存音频,已新建');
|
|
43
|
+
console.warn('未找到缓存音频,已新建', audioList);
|
|
44
|
+
debugger;
|
|
44
45
|
audio = new IAudio(blankAudioSrc);
|
|
45
46
|
audioList.push(audio);
|
|
46
47
|
}
|
|
47
48
|
if (src) {
|
|
48
|
-
console.log('set src: ' + src);
|
|
49
|
-
// audio.pause()
|
|
50
49
|
audio.src = src;
|
|
51
50
|
}
|
|
52
51
|
return audio;
|
|
@@ -77,30 +76,24 @@ function _waitForBlankAudioGenerated() {
|
|
|
77
76
|
if (!(audioList.some(function (audio) {
|
|
78
77
|
return !audio.ended && audio.src === blankAudioSrc;
|
|
79
78
|
}) && !isTimedOut)) {
|
|
80
|
-
_context.next =
|
|
79
|
+
_context.next = 13;
|
|
81
80
|
break;
|
|
82
81
|
}
|
|
83
82
|
if (!(Date.now() - startTime > timeout)) {
|
|
84
|
-
_context.next =
|
|
83
|
+
_context.next = 9;
|
|
85
84
|
break;
|
|
86
85
|
}
|
|
87
86
|
isTimedOut = true;
|
|
88
|
-
console.log('time out');
|
|
89
87
|
return _context.abrupt("return", Promise.resolve());
|
|
90
|
-
case
|
|
91
|
-
|
|
92
|
-
return audio.ended;
|
|
93
|
-
}));
|
|
94
|
-
_context.next = 13;
|
|
88
|
+
case 9:
|
|
89
|
+
_context.next = 11;
|
|
95
90
|
return new Promise(function (resolve) {
|
|
96
91
|
return setTimeout(resolve, checkInterval);
|
|
97
92
|
});
|
|
98
|
-
case
|
|
93
|
+
case 11:
|
|
99
94
|
_context.next = 5;
|
|
100
95
|
break;
|
|
101
|
-
case
|
|
102
|
-
console.log('audio init scuess!');
|
|
103
|
-
case 16:
|
|
96
|
+
case 13:
|
|
104
97
|
case "end":
|
|
105
98
|
return _context.stop();
|
|
106
99
|
}
|
|
@@ -118,7 +111,6 @@ function generateBlankAudio(length) {
|
|
|
118
111
|
}
|
|
119
112
|
}
|
|
120
113
|
function initAudio(audio) {
|
|
121
|
-
console.log('init audio');
|
|
122
114
|
if (audio.inited) return;
|
|
123
115
|
if (audio.src) {
|
|
124
116
|
audio.inited = true;
|
|
@@ -139,9 +131,7 @@ var IAudio = /*#__PURE__*/function (_Audio) {
|
|
|
139
131
|
_defineProperty(_assertThisInitialized(_this), "realSrc", '');
|
|
140
132
|
_defineProperty(_assertThisInitialized(_this), "inited", false);
|
|
141
133
|
_this.realSrc = src !== null && src !== void 0 ? src : '';
|
|
142
|
-
console.log('create audio', src);
|
|
143
134
|
_get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(IAudio.prototype)), "addEventListener", _thisSuper).call(_thisSuper, 'ended', function () {
|
|
144
|
-
console.log('ended', _this.realSrc, Date.now());
|
|
145
135
|
_this.src = '';
|
|
146
136
|
});
|
|
147
137
|
var init = function init() {
|