From 53f06eac15b3280d822fa425a730af22143d64c7 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 20 Aug 2020 18:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=B4=E6=92=AD=E6=B5=81?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scss/components/_video.scss | 15 +++++++++++++ scss/components/form/_tree.scss | 5 +++++ src/renderers/Video.tsx | 38 +++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/scss/components/_video.scss b/scss/components/_video.scss index 29349b783..2af6eec91 100644 --- a/scss/components/_video.scss +++ b/scss/components/_video.scss @@ -20,4 +20,19 @@ .video-react-paused .video-react-big-play-button.big-play-button-hide { display: block; } + + &-player { + position: relative; + } + + &-error { + position: absolute; + display: block; + width: 100%; + padding: 5px 10px; + color: $danger; + background: rgba(255, 255, 255, 0.4); + text-align: center; + top: 0; + } } diff --git a/scss/components/form/_tree.scss b/scss/components/form/_tree.scss index 682c1b677..caf43ccc0 100644 --- a/scss/components/form/_tree.scss +++ b/scss/components/form/_tree.scss @@ -96,6 +96,9 @@ &-itemInput { padding-left: $Tree-itemArrowWidth; + display: flex; + flex-direction: row; + flex-wrap: nowrap; > a { display: inline-block; @@ -110,6 +113,8 @@ } > input { + flex-grow: 1; + width: 100%; outline: none; background-color: $Form-input-bg; border: $Form-input-borderWidth solid $Form-input-borderColor; diff --git a/src/renderers/Video.tsx b/src/renderers/Video.tsx index 4f97714e6..c79c1621b 100644 --- a/src/renderers/Video.tsx +++ b/src/renderers/Video.tsx @@ -43,6 +43,7 @@ export interface FlvSourceProps { autoPlay?: boolean; actions?: any; order?: number; + setError: (error: string) => void; } // let currentPlaying: any = null; @@ -50,10 +51,18 @@ export interface FlvSourceProps { export class FlvSource extends React.Component { flvPlayer: any; componentDidMount() { - let {src, video, config, manager, isLive, autoPlay, actions} = this.props; + let { + src, + video, + config, + manager, + isLive, + autoPlay, + actions, + setError + } = this.props; (require as any)(['flv.js'], (flvjs: any) => { - // load hls video source base on hls.js if (flvjs.isSupported()) { video = video || (manager.video && manager.video.video); @@ -95,10 +104,10 @@ export class FlvSource extends React.Component { }); flvPlayer.on(flvjs.Events.RECOVERED_EARLY_EOF, () => { - alert('直播已经结束'); + setError('直播已经结束'); }); flvPlayer.on(flvjs.Events.ERROR, () => { - alert('视频加载失败'); + setError('视频加载失败'); }); if (autoPlay) { @@ -112,6 +121,7 @@ export class FlvSource extends React.Component { if (this.flvPlayer) { this.flvPlayer.unload(); this.flvPlayer.detachMediaElement(); + this.props.setError?.(''); } } @@ -202,6 +212,7 @@ export interface VideoProps extends RendererProps { export interface VideoState { posterInfo?: any; videoState?: any; + error?: string; } export default class Video extends React.Component { @@ -230,6 +241,7 @@ export default class Video extends React.Component { this.playerRef = this.playerRef.bind(this); this.onImageLoaded = this.onImageLoaded.bind(this); this.onClick = this.onClick.bind(this); + this.setError = this.setError.bind(this); } onImageLoaded(e: Event) { @@ -341,6 +353,16 @@ export default class Video extends React.Component { e.preventDefault(); } + setError(error?: string) { + const player = this.player; + + this.setState({ + error: error + }); + + player?.pause(); + } + renderFrames() { let { frames, @@ -441,7 +463,8 @@ export default class Video extends React.Component { playerClassName, classPrefix: ns, aspectRatio, - rates + rates, + classnames: cx } = this.props; let source = @@ -455,6 +478,7 @@ export default class Video extends React.Component { videoState.duration < minVideoDuration; let src = filter(source, data, '| raw'); let sourceNode; + const error = this.state.error; if ( (src && /\.flv(?:$|\?)/.test(src) && isLive) || @@ -466,6 +490,7 @@ export default class Video extends React.Component { order={999.0} isLive={isLive} src={src} + setError={this.setError} /> ); } else if ( @@ -478,7 +503,7 @@ export default class Video extends React.Component { } return ( -
+
{ + {error ?
{error}
: null} {highlight ? (

视频时长小于 {minVideoDuration} 秒