feat:add video block core

pr675
Hufe921 3 years ago
parent 867195a526
commit 5ba1c02f1f

@ -3,12 +3,13 @@ import { IRowElement } from '../../../../../interface/Row'
import { Draw } from '../../../Draw' import { Draw } from '../../../Draw'
import { BlockParticle } from '../BlockParticle' import { BlockParticle } from '../BlockParticle'
import { IFrameBlock } from './IFrameBlock' import { IFrameBlock } from './IFrameBlock'
import { VideoBlock } from './VideoBlock'
export class BaseBlock { export class BaseBlock {
private draw: Draw private draw: Draw
private element: IRowElement private element: IRowElement
private block: IFrameBlock | null private block: IFrameBlock | VideoBlock | null
private blockContainer: HTMLDivElement private blockContainer: HTMLDivElement
private blockItem: HTMLDivElement private blockItem: HTMLDivElement
@ -36,6 +37,9 @@ export class BaseBlock {
if (block.type === BlockType.IFRAME) { if (block.type === BlockType.IFRAME) {
this.block = new IFrameBlock(this.element) this.block = new IFrameBlock(this.element)
this.block.render(this.blockItem) this.block.render(this.blockItem)
} else if (block.type === BlockType.VIDEO) {
this.block = new VideoBlock(this.element)
this.block.render(this.blockItem)
} }
} }

@ -0,0 +1,23 @@
import { IRowElement } from '../../../../../interface/Row'
export class VideoBlock {
private element: IRowElement
constructor(element: IRowElement) {
this.element = element
}
public render(blockItemContainer: HTMLDivElement) {
const block = this.element.block!
const video = document.createElement('video')
video.style.width = '100%'
video.style.height = '100%'
video.style.objectFit = 'contain'
video.src = block.videoBlock?.src || ''
video.controls = true
video.crossOrigin = 'anonymous'
blockItemContainer.append(video)
}
}

@ -1,3 +1,4 @@
export enum BlockType { export enum BlockType {
IFRAME = 'iframe' IFRAME = 'iframe',
VIDEO = 'video'
} }

@ -4,7 +4,12 @@ export interface IIFrameBlock {
src: string; src: string;
} }
export interface IVideoBlock {
src: string;
}
export interface IBlock { export interface IBlock {
type: BlockType; type: BlockType;
iframeBlock?: IIFrameBlock; iframeBlock?: IIFrameBlock;
videoBlock?: IVideoBlock;
} }
Loading…
Cancel
Save