mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 20:21:20 -08:00
update gestureInit
This commit is contained in:
1 parent
c7a6e67940
commit
61cf68f0bc
3 files changed
+85
-25
No files matched your search
@@ -4137,6 +4137,21 @@ var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
||||
parcelHelpers.defineInteropFlag(exports);
|
||||
var _utils = require("../utils");
|
||||
var _progress = require("../control/progress");
|
||||
function GetSlideAngle(dx, dy) {
|
||||
return Math.atan2(dy, dx) * 180 / Math.PI;
|
||||
}
|
||||
function GetSlideDirection(startX, startY, endX, endY) {
|
||||
var dy = startY - endY;
|
||||
var dx = endX - startX;
|
||||
var result = 0;
|
||||
if (Math.abs(dx) < 2 && Math.abs(dy) < 2) return result;
|
||||
var angle = GetSlideAngle(dx, dy);
|
||||
if (angle >= -45 && angle < 45) result = 4;
|
||||
else if (angle >= 45 && angle < 135) result = 1;
|
||||
else if (angle >= -135 && angle < -45) result = 2;
|
||||
else if (angle >= 135 && angle <= 180 || angle >= -180 && angle < -135) result = 3;
|
||||
return result;
|
||||
}
|
||||
function gestureInit(art, events) {
|
||||
if ((0, _utils.isMobile) && !art.option.isLive) {
|
||||
const { $video , $progress } = art.template;
|
||||
@@ -4149,23 +4164,35 @@ function gestureInit(art, events) {
|
||||
if (event.touches.length === 1 && !art.isLock) {
|
||||
if (touchTarget === $progress) (0, _progress.setCurrentTime)(art, event);
|
||||
isDroging = true;
|
||||
const { clientX , clientY } = event.touches[0];
|
||||
startX = clientX;
|
||||
startY = clientY;
|
||||
const { pageX , pageY } = event.touches[0];
|
||||
startX = pageX;
|
||||
startY = pageY;
|
||||
startTime = art.currentTime;
|
||||
}
|
||||
};
|
||||
const onTouchMove = (event)=>{
|
||||
if (event.touches.length === 1 && isDroging && art.duration) {
|
||||
const { clientX , clientY } = event.touches[0];
|
||||
const ratioX = (0, _utils.clamp)((clientX - startX) / art.width, -1, 1);
|
||||
const ratioY = (0, _utils.clamp)((clientY - startY) / art.height, -1, 1);
|
||||
const ratio = art.isRotate ? ratioY : ratioX;
|
||||
const TOUCH_MOVE_RATIO = touchTarget === $video ? art.constructor.TOUCH_MOVE_RATIO : 1;
|
||||
const currentTime = (0, _utils.clamp)(startTime + art.duration * ratio * TOUCH_MOVE_RATIO, 0, art.duration);
|
||||
art.seek = currentTime;
|
||||
art.emit("setBar", "played", (0, _utils.clamp)(currentTime / art.duration, 0, 1));
|
||||
art.notice.show = `${(0, _utils.secondToTime)(currentTime)} / ${(0, _utils.secondToTime)(art.duration)}`;
|
||||
const { pageX , pageY } = event.touches[0];
|
||||
const direction = GetSlideDirection(startX, startY, pageX, pageY);
|
||||
const isHorizontal = [
|
||||
3,
|
||||
4
|
||||
].includes(direction);
|
||||
const isVertical = [
|
||||
1,
|
||||
2
|
||||
].includes(direction);
|
||||
const isLegal = isHorizontal && !art.isRotate || isVertical && art.isRotate;
|
||||
if (isLegal) {
|
||||
const ratioX = (0, _utils.clamp)((pageX - startX) / art.width, -1, 1);
|
||||
const ratioY = (0, _utils.clamp)((pageY - startY) / art.height, -1, 1);
|
||||
const ratio = art.isRotate ? ratioY : ratioX;
|
||||
const TOUCH_MOVE_RATIO = touchTarget === $video ? art.constructor.TOUCH_MOVE_RATIO : 1;
|
||||
const currentTime = (0, _utils.clamp)(startTime + art.duration * ratio * TOUCH_MOVE_RATIO, 0, art.duration);
|
||||
art.seek = currentTime;
|
||||
art.emit("setBar", "played", (0, _utils.clamp)(currentTime / art.duration, 0, 1));
|
||||
art.notice.show = `${(0, _utils.secondToTime)(currentTime)} / ${(0, _utils.secondToTime)(art.duration)}`;
|
||||
}
|
||||
}
|
||||
};
|
||||
const onTouchEnd = ()=>{
|
||||
|
||||
Reference in new issue
Block a user