feat: 视频插件移动端优化
This commit is contained in:
1 parent
cba20150be
commit
65c17a8ce3
2 files changed
+86
-93
No files matched your search
@@ -52,19 +52,22 @@ const { setVideo } = (() => {
|
|||||||
videoFillMode: 'contain',
|
videoFillMode: 'contain',
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
download: true,
|
download: true,
|
||||||
|
ignores: [videos.length === 0 ? 'playNext' : undefined].filter(v => v) as string[],
|
||||||
|
lang: 'zh-cn',
|
||||||
|
playbackRate: [0.1, 0.3, 0.5, 0.75, 1, 1.5, 2, 3, 5, 10],
|
||||||
|
texttrack,
|
||||||
screenShot: {
|
screenShot: {
|
||||||
saveImg: true,
|
saveImg: true,
|
||||||
quality: 1,
|
quality: 1,
|
||||||
type: 'image/png',
|
type: 'image/png',
|
||||||
format: '.png'
|
format: '.png'
|
||||||
},
|
},
|
||||||
lang: 'zh-cn',
|
|
||||||
playbackRate: [0.1, 0.3, 0.5, 0.75, 1, 1.5, 2, 3, 5, 10],
|
|
||||||
playNext: {
|
playNext: {
|
||||||
urlList: videos.map(v => v.url)
|
urlList: videos.map(v => v.url)
|
||||||
},
|
},
|
||||||
texttrack,
|
progress: {
|
||||||
ignores: [videos.length === 0 ? 'playNext' : undefined].filter(v => v) as string[]
|
isDragingSeek: true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,109 +1,99 @@
|
|||||||
import { BasePlugin } from 'xgplayer'
|
import { BasePlugin } from "xgplayer";
|
||||||
import './lockScreen.scss'
|
import "./lockScreen.scss";
|
||||||
|
import MobilePlugin from "xgplayer/es/plugins/mobile";
|
||||||
|
|
||||||
export default class LockPlugin extends BasePlugin {
|
export default class LockPlugin extends BasePlugin {
|
||||||
static get pluginName() {
|
static get pluginName() {
|
||||||
return 'lockPlugin'
|
return "lockPlugin";
|
||||||
}
|
}
|
||||||
|
|
||||||
private locked: boolean
|
private locked: boolean;
|
||||||
private lockDiv: HTMLDivElement | null = null
|
private lockDiv: HTMLDivElement | null = null;
|
||||||
private overlayDiv: HTMLDivElement | null = null
|
private overlayDiv: HTMLDivElement | null = null;
|
||||||
|
|
||||||
private lockOpenSVG: string = `
|
private lockOpenSVG: string = `
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||||
<path d="M336 208v-95a80 80 0 0 0-160 0v95" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></path>
|
<path d="M336 208v-95a80 80 0 0 0-160 0v95" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></path>
|
||||||
<rect x="96" y="208" width="320" height="272" rx="48" ry="48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></rect>
|
<rect x="96" y="208" width="320" height="272" rx="48" ry="48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></rect>
|
||||||
</svg>`
|
</svg>`;
|
||||||
|
|
||||||
private lockClosedSVG: string = `
|
private lockClosedSVG: string = `
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||||
<path d="M336 112a80 80 0 0 0-160 0v96" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></path>
|
<path d="M336 112a80 80 0 0 0-160 0v96" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></path>
|
||||||
<rect x="96" y="208" width="320" height="272" rx="48" ry="48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></rect>
|
<rect x="96" y="208" width="320" height="272" rx="48" ry="48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"></rect>
|
||||||
</svg>`
|
</svg>`;
|
||||||
|
|
||||||
constructor(args: any) {
|
constructor(args: any) {
|
||||||
super(args)
|
super(args);
|
||||||
this.locked = false
|
this.locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterCreate() {
|
afterCreate() {
|
||||||
this.createLockDiv()
|
this.createLockDiv();
|
||||||
this.createOverlayDiv()
|
this.createOverlayDiv();
|
||||||
this.bindEvents()
|
this.bindEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private createLockDiv() {
|
private createLockDiv() {
|
||||||
this.lockDiv = document.createElement('div')
|
this.lockDiv = document.createElement("div");
|
||||||
this.lockDiv.innerHTML = this.lockClosedSVG
|
this.lockDiv.innerHTML = this.lockClosedSVG;
|
||||||
this.lockDiv.className = 'lock-div'
|
this.lockDiv.className = "lock-div";
|
||||||
this.player.root !== null && this.player.root.appendChild(this.lockDiv)
|
this.player.root !== null && this.player.root.appendChild(this.lockDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
private createOverlayDiv() {
|
private createOverlayDiv() {
|
||||||
this.overlayDiv = document.createElement('div')
|
this.overlayDiv = document.createElement("div");
|
||||||
this.overlayDiv.className = 'overlay-div'
|
this.overlayDiv.className = "overlay-div";
|
||||||
this.player.root !== null &&
|
this.player.root !== null && this.player.root.appendChild(this.overlayDiv);
|
||||||
this.player.root.appendChild(this.overlayDiv)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private bindEvents() {
|
private bindEvents() {
|
||||||
this.lockDiv!.addEventListener('click', this.toggleLock.bind(this))
|
this.lockDiv!.addEventListener("click", this.toggleLock.bind(this));
|
||||||
this.player.root !== null &&
|
this.player.root !== null && this.player.root.addEventListener("click", this.preventClick.bind(this), true);
|
||||||
this.player.root.addEventListener(
|
this.player.usePluginHooks("progress", "dragstart", () => {
|
||||||
'click',
|
if (this.locked) {
|
||||||
this.preventClick.bind(this),
|
return false;
|
||||||
true
|
}
|
||||||
)
|
return true;
|
||||||
}
|
});
|
||||||
|
// 阻止进度条默认行为
|
||||||
private toggleLock() {
|
for(const event of ['dragstart', 'drag', 'dragend']) {
|
||||||
console.log(this.player.seek)
|
this.player.usePluginHooks("progress", event, () => {
|
||||||
this.player.seek = () => {}
|
if (this.locked) {
|
||||||
if (this.lockDiv && this.overlayDiv) {
|
return false;
|
||||||
this.locked = !this.locked
|
}
|
||||||
this.lockDiv.innerHTML = this.locked
|
return true;
|
||||||
? this.lockOpenSVG
|
});
|
||||||
: this.lockClosedSVG
|
|
||||||
this.overlayDiv.style.display = this.locked ? 'block' : 'none'
|
|
||||||
this.player.controls &&
|
|
||||||
(this.locked
|
|
||||||
? this.player.controls.hide()
|
|
||||||
: this.player.controls.show())
|
|
||||||
this.player.root !== null &&
|
|
||||||
this.player.root.classList.toggle('xgplayer-locked', this.locked)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private preventClick(event: MouseEvent) {
|
private toggleLock() {
|
||||||
if (
|
const mobile = this.getPlugin('mobile') as MobilePlugin | undefined
|
||||||
this.locked &&
|
if (this.lockDiv && this.overlayDiv) {
|
||||||
event.target instanceof HTMLElement &&
|
this.locked = !this.locked;
|
||||||
!event.target.classList.contains('lock-div')
|
this.lockDiv.innerHTML = this.locked ? this.lockOpenSVG : this.lockClosedSVG;
|
||||||
) {
|
this.overlayDiv.style.display = this.locked ? "block" : "none";
|
||||||
event.stopPropagation()
|
this.player.controls && (this.locked ? this.player.controls.hide() : this.player.controls.show());
|
||||||
event.preventDefault()
|
this.player.root !== null && this.player.root.classList.toggle("xgplayer-locked", this.locked);
|
||||||
}
|
this.locked ? mobile?.disableGesture() : mobile?.enableGesture()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
private preventClick(event: MouseEvent) {
|
||||||
if (this.lockDiv) {
|
if (this.locked && event.target instanceof HTMLElement && !event.target.classList.contains("lock-div")) {
|
||||||
this.lockDiv.removeEventListener(
|
event.stopPropagation();
|
||||||
'click',
|
event.preventDefault();
|
||||||
this.toggleLock.bind(this)
|
}
|
||||||
)
|
}
|
||||||
this.player.root !== null &&
|
|
||||||
this.player.root.removeEventListener(
|
destroy() {
|
||||||
'click',
|
if (this.lockDiv) {
|
||||||
this.preventClick.bind(this),
|
this.lockDiv.removeEventListener("click", this.toggleLock.bind(this));
|
||||||
true
|
this.player.root !== null && this.player.root.removeEventListener("click", this.preventClick.bind(this), true);
|
||||||
)
|
this.player.root !== null && this.player.root.removeChild(this.lockDiv);
|
||||||
this.player.root !== null &&
|
}
|
||||||
this.player.root.removeChild(this.lockDiv)
|
if (this.overlayDiv) {
|
||||||
}
|
this.player.root !== null && this.player.root.removeChild(this.overlayDiv);
|
||||||
if (this.overlayDiv) {
|
}
|
||||||
this.player.root !== null &&
|
}
|
||||||
this.player.root.removeChild(this.overlayDiv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user