优化playing

This commit is contained in:
Harvey Zack committed 2018-11-28 14:28:45 +08:00
1 parent 8dfe97b905
commit bdb050f0a7
11 files changed
+43 -36

No files matched your search

@@ -3,6 +3,7 @@ import { debounce } from '../utils';
export default function mousemoveInitInit(art, events) {
const {
template: { $player, $video },
player
} = art;
const autoHide = debounce(() => {
@@ -12,7 +13,7 @@ export default function mousemoveInitInit(art, events) {
}, 5000);
art.on('hoverleave', () => {
if (art.isPlaying) {
if (player.playing) {
autoHide();
}
});
@@ -21,7 +22,7 @@ export default function mousemoveInitInit(art, events) {
autoHide.clearTimeout();
$player.classList.remove('artplayer-hide-cursor');
art.controls.show();
if (!art.player.pipState && art.isPlaying && event.target === $video) {
if (!art.player.pipState && player.playing && event.target === $video) {
autoHide();
}
});
-1
View File
@@ -108,7 +108,6 @@ class Artplayer extends Emitter {
init() {
this.isFocus = false;
this.isPlaying = false;
this.whitelist = new Whitelist(this);
this.template = new Template(this);
@@ -55,7 +55,6 @@ export default function eventInit(art, player) {
// });
art.on('video:ended', () => {
art.isPlaying = false;
art.controls.show();
art.mask.show();
if (option.loop) {
@@ -72,7 +71,6 @@ export default function eventInit(art, player) {
notice.show(`${i18n.get('Reconnect')}: ${reconnectTime}`);
});
} else {
art.isPlaying = false;
art.loading.hide();
art.controls.hide();
$player.classList.add('artplayer-error');
@@ -98,19 +96,16 @@ export default function eventInit(art, player) {
});
art.on('video:pause', () => {
art.isPlaying = false;
art.controls.show();
art.mask.show();
});
art.on('video:play', () => {
art.isPlaying = true;
art.controls.hide();
art.mask.hide();
});
art.on('video:playing', () => {
art.isPlaying = true;
art.controls.hide();
art.mask.hide();
});
+2
View File
@@ -17,6 +17,7 @@ import fullscreenWebMix from './fullscreenWebMix';
import pipMix from './pipMix';
import loadedMix from './loadedMix';
import playedMix from './playedMix';
import playingMix from './playingMix';
import autoSizeMix from './autoSizeMix';
import flipMix from './flipMix';
@@ -41,6 +42,7 @@ export default class Player {
pipMix(art, this);
loadedMix(art, this);
playedMix(art, this);
playingMix(art, this);
autoSizeMix(art, this);
flipMix(art, this);
}
+1 -1
View File
@@ -38,7 +38,7 @@ function nativePip(art, player) {
proxy($video, 'leavepictureinpicture', () => {
art.emit('pipExit');
if (art.isPlaying) {
if (player.playing) {
player.play();
}
});
@@ -0,0 +1,6 @@
export default function playingMix(art, player) {
const { $video } = art.template;
Object.defineProperty(player, 'playing', {
get: () => !!($video.currentTime > 0 && !$video.paused && !$video.ended && $video.readyState > 2),
});
}
@@ -8,14 +8,13 @@ export default function switchMix(art, player) {
Object.defineProperty(player, 'switchQuality', {
value: (url, name = 'unknown') => {
if (url !== option.url) {
const { isPlaying } = art;
const { currentTime } = player;
const { currentTime, playing } = player;
player.attachUrl(url).then(() => {
option.url = url;
player.playbackRateRemove();
player.aspectRatioRemove();
player.seek(currentTime);
if (isPlaying) {
if (playing) {
player.play();
}
notice.show(`${i18n.get('Switch video')}: ${name}`);
+1 -1
View File
@@ -1,7 +1,7 @@
export default function toggleMix(art, player) {
Object.defineProperty(player, 'toggle', {
value: () => {
if (art.isPlaying) {
if (player.playing) {
player.pause();
} else {
player.play();