mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-14 08:26:16 -08:00
add getPosFromEventMobile
This commit is contained in:
1 parent
8549661327
commit
e862f8d56c
5 files changed
+90
-18
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { errorHandle, addClass, removeClass } from '../utils';
|
||||
import { errorHandle, addClass, removeClass, isMobile } from '../utils';
|
||||
import Component from '../utils/component';
|
||||
import fullscreen from './fullscreen';
|
||||
import fullscreenWeb from './fullscreenWeb';
|
||||
@@ -55,7 +55,7 @@ export default class Control extends Component {
|
||||
this.add(
|
||||
thumbnails({
|
||||
name: 'thumbnails',
|
||||
disable: !option.thumbnails.url || option.isLive,
|
||||
disable: !option.thumbnails.url || option.isLive || isMobile,
|
||||
position: 'top',
|
||||
index: 20,
|
||||
}),
|
||||
@@ -109,7 +109,7 @@ export default class Control extends Component {
|
||||
this.add(
|
||||
screenshot({
|
||||
name: 'screenshot',
|
||||
disable: !option.screenshot,
|
||||
disable: !option.screenshot || isMobile,
|
||||
position: 'right',
|
||||
index: 20,
|
||||
}),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { query, clamp, append, setStyle, setStyles, secondToTime, includeFromEve
|
||||
export function getPosFromEvent(art, event) {
|
||||
const { $progress } = art.template;
|
||||
const { left } = $progress.getBoundingClientRect();
|
||||
const eventLeft = typeof event.pageX === 'number' ? event.pageX : event.touches[0].clientX;
|
||||
const eventLeft = event.pageX;
|
||||
const width = clamp(eventLeft - left, 0, $progress.clientWidth);
|
||||
const second = (width / $progress.clientWidth) * art.duration;
|
||||
const time = secondToTime(second);
|
||||
@@ -11,6 +11,27 @@ export function getPosFromEvent(art, event) {
|
||||
return { second, time, width, percentage };
|
||||
}
|
||||
|
||||
export function getPosFromEventMobile(art, event) {
|
||||
const autoOrientation = art.plugins.autoOrientation && art.plugins.autoOrientation.state;
|
||||
|
||||
const { $progress } = art.template;
|
||||
const { left, top } = $progress.getBoundingClientRect();
|
||||
const { clientX, clientY } = event.touches[0];
|
||||
|
||||
const width = clamp(clientX - left, 0, $progress.clientWidth);
|
||||
const height = clamp(clientY - top, 0, $progress.clientWidth);
|
||||
const size = autoOrientation ? height : width;
|
||||
|
||||
const secondX = (width / $progress.clientWidth) * art.duration;
|
||||
const secondY = (height / $progress.clientWidth) * art.duration;
|
||||
const second = autoOrientation ? secondY : secondX;
|
||||
|
||||
const time = secondToTime(second);
|
||||
const percentage = clamp(size / $progress.clientWidth, 0, 1);
|
||||
|
||||
return { second, time, size, percentage };
|
||||
}
|
||||
|
||||
export default function progress(options) {
|
||||
return (art) => {
|
||||
const {
|
||||
@@ -164,7 +185,8 @@ export default function progress(options) {
|
||||
|
||||
proxy(document, 'touchmove', (event) => {
|
||||
if (event.touches.length === 1 && isDroging) {
|
||||
const { second, percentage } = getPosFromEvent(art, event);
|
||||
const { second, percentage } = getPosFromEventMobile(art, event);
|
||||
console.log(second, percentage);
|
||||
setBar('played', percentage);
|
||||
art.seek = second;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@ export default function gestureInit(art, events) {
|
||||
|
||||
let isDroging = false;
|
||||
let startX = 0;
|
||||
let startY = 0;
|
||||
let currentTime = 0;
|
||||
let pressTimer = null;
|
||||
|
||||
events.proxy($video, 'touchstart', (event) => {
|
||||
if (event.touches.length === 1) {
|
||||
isDroging = true;
|
||||
startX = event.touches[0].clientX;
|
||||
const { clientX, clientY } = event.touches[0];
|
||||
startX = clientX;
|
||||
startY = clientY;
|
||||
|
||||
clearTimeout(pressTimer);
|
||||
pressTimer = setTimeout(() => {
|
||||
@@ -26,11 +29,16 @@ export default function gestureInit(art, events) {
|
||||
|
||||
events.proxy($video, 'touchmove', (event) => {
|
||||
if (event.touches.length === 1 && isDroging) {
|
||||
const { clientX } = event.touches[0];
|
||||
const { clientX, clientY } = event.touches[0];
|
||||
const ratioX = clamp((clientX - startX) / art.width, -1, 1);
|
||||
const ratioY = clamp((clientY - startY) / art.height, -1, 1);
|
||||
|
||||
if (art.duration) {
|
||||
currentTime = clamp(art.currentTime + art.duration * ratioX, 0, art.duration);
|
||||
if (art.plugins.autoOrientation && art.plugins.autoOrientation.state) {
|
||||
currentTime = clamp(art.currentTime + art.duration * ratioY, 0, art.duration);
|
||||
} else {
|
||||
currentTime = clamp(art.currentTime + art.duration * ratioX, 0, art.duration);
|
||||
}
|
||||
notice.show = `${secondToTime(currentTime)} / ${secondToTime(art.duration)}`;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +55,7 @@ export default function gestureInit(art, events) {
|
||||
}
|
||||
|
||||
startX = 0;
|
||||
startY = 0;
|
||||
currentTime = 0;
|
||||
isDroging = false;
|
||||
clearTimeout(pressTimer);
|
||||
|
||||
Reference in new issue
Block a user