mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 16:11:20 -08:00
优化整体结构
This commit is contained in:
1 parent
9f9cb0e036
commit
487e865017
34 files changed
+505
-427
No files matched your search
@@ -1,8 +1,14 @@
|
||||
import { clamp, errorHandle } from '../utils';
|
||||
|
||||
export default function currentTimeMix(art, player) {
|
||||
Object.defineProperty(player, 'currentTime', {
|
||||
get: () => art.template.$video.currentTime || 0,
|
||||
set: currentTime => {
|
||||
art.template.$video.currentTime = currentTime;
|
||||
errorHandle(
|
||||
player.duration,
|
||||
'Cannot set current time, the video seems to be not ready for mate information.',
|
||||
);
|
||||
art.template.$video.currentTime = clamp(currentTime, 0, player.duration);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import loadedMix from './loadedMix';
|
||||
import playedMix from './playedMix';
|
||||
import playingMix from './playingMix';
|
||||
import autoSizeMix from './autoSizeMix';
|
||||
import rectMix from './rectMix';
|
||||
import flipMix from './flipMix';
|
||||
|
||||
export default class Player {
|
||||
@@ -44,6 +45,8 @@ export default class Player {
|
||||
playedMix(art, this);
|
||||
playingMix(art, this);
|
||||
autoSizeMix(art, this);
|
||||
rectMix(art, this);
|
||||
flipMix(art, this);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export default function rectMix(art, player) {
|
||||
Object.defineProperty(player, 'rect', {
|
||||
get: () => {
|
||||
return art.template.$player.getBoundingClientRect();
|
||||
},
|
||||
});
|
||||
|
||||
['bottom', 'height', 'left', 'right', 'top', 'width', 'x', 'y'].forEach(key => {
|
||||
Object.defineProperty(player, key, {
|
||||
get: () => {
|
||||
return player.rect[key];
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -5,13 +5,9 @@ export default function seekMix(art, player) {
|
||||
|
||||
Object.defineProperty(player, 'seek', {
|
||||
value: time => {
|
||||
let newTime = Math.max(time, 0);
|
||||
if (player.duration) {
|
||||
newTime = Math.min(newTime, player.duration);
|
||||
}
|
||||
player.currentTime = newTime;
|
||||
notice.show(`${secondToTime(newTime)} / ${secondToTime(player.duration)}`);
|
||||
art.emit('seek', newTime);
|
||||
player.currentTime = time;
|
||||
notice.show(`${secondToTime(time)} / ${secondToTime(player.duration)}`);
|
||||
art.emit('seek', time);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -11,14 +11,12 @@ export default function volumeMix(art, player) {
|
||||
Object.defineProperty(player, 'volume', {
|
||||
get: () => $video.volume || 0,
|
||||
set: percentage => {
|
||||
if (percentage !== undefined) {
|
||||
$video.volume = clamp(percentage, 0, 1);
|
||||
notice.show(`${i18n.get('Volume')}: ${parseInt($video.volume * 100, 10)}`);
|
||||
if ($video.volume !== 0) {
|
||||
storage.set('volume', $video.volume);
|
||||
}
|
||||
art.emit('volumeChange', $video.volume);
|
||||
$video.volume = clamp(percentage, 0, 1);
|
||||
notice.show(`${i18n.get('Volume')}: ${parseInt($video.volume * 100, 10)}`);
|
||||
if ($video.volume !== 0) {
|
||||
storage.set('volume', $video.volume);
|
||||
}
|
||||
art.emit('volumeChange', $video.volume);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user