优化整体结构

This commit is contained in:
Harvey Zack committed 2019-04-30 13:06:24 +08:00
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);
},
});
}
+3
View File
@@ -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);
}
}
+15
View File
@@ -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];
},
});
});
}
+3 -7
View File
@@ -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);
},
});
}
+5 -7
View File
@@ -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);
},
});