优化pip

This commit is contained in:
Harvey committed 2019-09-19 15:13:57 +08:00
1 parent fcd7fbecfc
commit 022f36624a
2 files changed
+13 -4

No files matched your search

+10 -3
View File
@@ -4,6 +4,7 @@ function nativePip(art, player) {
const {
template: { $video },
events: { proxy },
notice,
} = art;
$video.disablePictureInPicture = false;
@@ -15,10 +16,12 @@ function nativePip(art, player) {
set(value) {
if (value) {
$video.requestPictureInPicture().catch(error => {
notice.show(error);
throw error;
});
} else {
document.exitPictureInPicture().catch(error => {
notice.show(error);
throw error;
});
}
@@ -75,6 +78,7 @@ function customPip(art, player) {
let lastPageY = 0;
let lastPlayerLeft = 0;
let lastPlayerTop = 0;
proxy($pipHeader, 'mousedown', event => {
isDroging = true;
lastPageX = event.pageX;
@@ -103,7 +107,8 @@ function customPip(art, player) {
});
append($pipTitle, option.title || i18n.get('Mini player'));
Object.defineProperty(player, 'pip', {
const property = {
get() {
return $player.classList.contains('artplayer-pip');
},
@@ -133,14 +138,16 @@ function customPip(art, player) {
art.emit('pipExit');
}
},
});
};
Object.defineProperty(player, 'pip', property);
}
export default function pipMix(art, player) {
const { $video } = art.template;
if (document.pictureInPictureEnabled) {
nativePip(art, player);
} else if ($video.webkitSupportsPresentationMode && typeof $video.webkitSetPresentationMode === 'function') {
} else if ($video.webkitSupportsPresentationMode) {
webkitPip(art, player);
} else {
customPip(art, player);
+3 -1
View File
@@ -2,9 +2,10 @@ import { debounce } from '../utils';
export default function autoPip(art) {
const { events, player, template } = art;
const scrollDebounce = debounce(() => {
const { top, height } = template.$player.getBoundingClientRect();
if (top + height <= 0 && !player.pip && player.playing) {
if (top + height <= 0 && !player.pip) {
player.pip = true;
art.emit('artplayerPluginAutoPip', true);
} else if (player.pip) {
@@ -12,6 +13,7 @@ export default function autoPip(art) {
art.emit('artplayerPluginAutoPip', false);
}
}, 300);
events.proxy(window, 'scroll', scrollDebounce);
return {