Skip to content

Commit 0cd8c67

Browse files
修复videolayer 播放流或者缓冲卡顿时,画面与视频位置更新不同步
1 parent ba826b7 commit 0cd8c67

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/mapboxgl/overlay/VideoLayer.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
this.renderingMode = '3d';
9797
this.overlay = true;
9898
if (Array.isArray(this.videoParameters)) {
99-
this.videoParameters = smartTimeProcessor(this.interval, this.videoParameters, ['yaw', 'pitch', 'roll', 'x', 'y', 'z', 'extent']);
99+
this.videoParameters = smartTimeProcessor(this.interval, this.videoParameters, ['yaw', 'pitch', 'roll', 'x', 'y', 'z', 'extent']);
100100
const timeArr = this.videoParameters.map((item) => {
101101
return item.time;
102102
})
@@ -271,32 +271,43 @@
271271
let canvas = document.createElement('canvas');
272272
let { clipMat, dst1 } = this._updateMask(canvas, that.timeParams[0].realHeight, that.timeParams[0].ratio);
273273
let count = 0;
274+
const videoEle = this.video.tech().el();
275+
let current = 0;
276+
if (this.videoParameters.length > 1) {
277+
const updateCanvas = (now, metadata) => {
278+
current = metadata.mediaTime;
279+
videoEle.requestVideoFrameCallback(updateCanvas);
280+
};
281+
282+
videoEle.requestVideoFrameCallback(updateCanvas);
283+
}
274284
map.addSource(this.layerId, {
275285
type: 'video',
276286
urls: [url],
277287
drawImageCallback(frame) {
278-
const current = that.video.currentTime();
279288
if (that.videoParameters.length > 1) {
289+
current = that.video.currentTime();
280290
let res = that.finder.findNearest(current);
281291
if (res) {
282292
count = res.value;
283293
}
284-
}
285-
if (that.videoParameters.length > 1 && count) {
286-
let curData = that.timeParams[count];
287-
count = 0;
288-
if (curData) {
289-
that.dsize = curData.dsize;
290-
dstTri = curData.dstTri;
291-
result = curData.result;
292-
setTimeout(() => {
293-
that.map.getSource(that.layerId).setCoordinates([
294-
[result[0], result[3]],
295-
[result[2], result[3]],
296-
[result[2], result[1]],
297-
[result[0], result[1]]
298-
])
299-
}, 0);
294+
295+
if (count) {
296+
let curData = that.timeParams[count];
297+
count = 0;
298+
if (curData) {
299+
that.dsize = curData.dsize;
300+
dstTri = curData.dstTri;
301+
result = curData.result;
302+
setTimeout(() => {
303+
that.map.getSource(that.layerId).setCoordinates([
304+
[result[0], result[3]],
305+
[result[2], result[3]],
306+
[result[2], result[1]],
307+
[result[0], result[1]]
308+
])
309+
}, 0);
310+
}
300311
}
301312
}
302313
let src = that.cv.matFromImageData(frame);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy