forked from p96170835/amis
优化直播流错误显示
This commit is contained in:
parent
5b8bc2d723
commit
53f06eac15
|
@ -20,4 +20,19 @@
|
||||||
.video-react-paused .video-react-big-play-button.big-play-button-hide {
|
.video-react-paused .video-react-big-play-button.big-play-button-hide {
|
||||||
display: block;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,9 @@
|
||||||
|
|
||||||
&-itemInput {
|
&-itemInput {
|
||||||
padding-left: $Tree-itemArrowWidth;
|
padding-left: $Tree-itemArrowWidth;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
|
||||||
> a {
|
> a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -110,6 +113,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
> input {
|
> input {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 100%;
|
||||||
outline: none;
|
outline: none;
|
||||||
background-color: $Form-input-bg;
|
background-color: $Form-input-bg;
|
||||||
border: $Form-input-borderWidth solid $Form-input-borderColor;
|
border: $Form-input-borderWidth solid $Form-input-borderColor;
|
||||||
|
|
|
@ -43,6 +43,7 @@ export interface FlvSourceProps {
|
||||||
autoPlay?: boolean;
|
autoPlay?: boolean;
|
||||||
actions?: any;
|
actions?: any;
|
||||||
order?: number;
|
order?: number;
|
||||||
|
setError: (error: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let currentPlaying: any = null;
|
// let currentPlaying: any = null;
|
||||||
|
@ -50,10 +51,18 @@ export interface FlvSourceProps {
|
||||||
export class FlvSource extends React.Component<FlvSourceProps, any> {
|
export class FlvSource extends React.Component<FlvSourceProps, any> {
|
||||||
flvPlayer: any;
|
flvPlayer: any;
|
||||||
componentDidMount() {
|
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) => {
|
(require as any)(['flv.js'], (flvjs: any) => {
|
||||||
// load hls video source base on hls.js
|
|
||||||
if (flvjs.isSupported()) {
|
if (flvjs.isSupported()) {
|
||||||
video = video || (manager.video && manager.video.video);
|
video = video || (manager.video && manager.video.video);
|
||||||
|
|
||||||
|
@ -95,10 +104,10 @@ export class FlvSource extends React.Component<FlvSourceProps, any> {
|
||||||
});
|
});
|
||||||
|
|
||||||
flvPlayer.on(flvjs.Events.RECOVERED_EARLY_EOF, () => {
|
flvPlayer.on(flvjs.Events.RECOVERED_EARLY_EOF, () => {
|
||||||
alert('直播已经结束');
|
setError('直播已经结束');
|
||||||
});
|
});
|
||||||
flvPlayer.on(flvjs.Events.ERROR, () => {
|
flvPlayer.on(flvjs.Events.ERROR, () => {
|
||||||
alert('视频加载失败');
|
setError('视频加载失败');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (autoPlay) {
|
if (autoPlay) {
|
||||||
|
@ -112,6 +121,7 @@ export class FlvSource extends React.Component<FlvSourceProps, any> {
|
||||||
if (this.flvPlayer) {
|
if (this.flvPlayer) {
|
||||||
this.flvPlayer.unload();
|
this.flvPlayer.unload();
|
||||||
this.flvPlayer.detachMediaElement();
|
this.flvPlayer.detachMediaElement();
|
||||||
|
this.props.setError?.('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +212,7 @@ export interface VideoProps extends RendererProps {
|
||||||
export interface VideoState {
|
export interface VideoState {
|
||||||
posterInfo?: any;
|
posterInfo?: any;
|
||||||
videoState?: any;
|
videoState?: any;
|
||||||
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Video extends React.Component<VideoProps, VideoState> {
|
export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
|
@ -230,6 +241,7 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
this.playerRef = this.playerRef.bind(this);
|
this.playerRef = this.playerRef.bind(this);
|
||||||
this.onImageLoaded = this.onImageLoaded.bind(this);
|
this.onImageLoaded = this.onImageLoaded.bind(this);
|
||||||
this.onClick = this.onClick.bind(this);
|
this.onClick = this.onClick.bind(this);
|
||||||
|
this.setError = this.setError.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
onImageLoaded(e: Event) {
|
onImageLoaded(e: Event) {
|
||||||
|
@ -341,6 +353,16 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setError(error?: string) {
|
||||||
|
const player = this.player;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
error: error
|
||||||
|
});
|
||||||
|
|
||||||
|
player?.pause();
|
||||||
|
}
|
||||||
|
|
||||||
renderFrames() {
|
renderFrames() {
|
||||||
let {
|
let {
|
||||||
frames,
|
frames,
|
||||||
|
@ -441,7 +463,8 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
playerClassName,
|
playerClassName,
|
||||||
classPrefix: ns,
|
classPrefix: ns,
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
rates
|
rates,
|
||||||
|
classnames: cx
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
let source =
|
let source =
|
||||||
|
@ -455,6 +478,7 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
videoState.duration < minVideoDuration;
|
videoState.duration < minVideoDuration;
|
||||||
let src = filter(source, data, '| raw');
|
let src = filter(source, data, '| raw');
|
||||||
let sourceNode;
|
let sourceNode;
|
||||||
|
const error = this.state.error;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(src && /\.flv(?:$|\?)/.test(src) && isLive) ||
|
(src && /\.flv(?:$|\?)/.test(src) && isLive) ||
|
||||||
|
@ -466,6 +490,7 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
order={999.0}
|
order={999.0}
|
||||||
isLive={isLive}
|
isLive={isLive}
|
||||||
src={src}
|
src={src}
|
||||||
|
setError={this.setError}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -478,7 +503,7 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={playerClassName}>
|
<div className={cx('Video-player', playerClassName)}>
|
||||||
<Player
|
<Player
|
||||||
ref={this.playerRef}
|
ref={this.playerRef}
|
||||||
poster={filter(poster, data, '| raw')}
|
poster={filter(poster, data, '| raw')}
|
||||||
|
@ -497,6 +522,7 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
<Shortcut disabled />
|
<Shortcut disabled />
|
||||||
</Player>
|
</Player>
|
||||||
|
|
||||||
|
{error ? <div className={cx('Video-error')}>{error}</div> : null}
|
||||||
{highlight ? (
|
{highlight ? (
|
||||||
<p className={`m-t-xs ${ns}Text--danger`}>
|
<p className={`m-t-xs ${ns}Text--danger`}>
|
||||||
视频时长小于 {minVideoDuration} 秒
|
视频时长小于 {minVideoDuration} 秒
|
||||||
|
|
Loading…
Reference in New Issue