Video frames 功能调整
This commit is contained in:
parent
cf01d8603d
commit
460a81527f
|
@ -1,16 +1,23 @@
|
||||||
export default {
|
export default {
|
||||||
$schema: "https://houtai.baidu.com/v2/schemas/page.json#",
|
$schema: 'https://houtai.baidu.com/v2/schemas/page.json#',
|
||||||
title: "视频播放器",
|
title: '视频播放器',
|
||||||
body: [
|
body: [
|
||||||
'<p class="text-danger">另外还支持直播流, flv 和 hls 格式</p>',
|
'<p class="text-danger">另外还支持直播流, flv 和 hls 格式</p>',
|
||||||
{
|
{
|
||||||
type: "video",
|
type: 'video',
|
||||||
autoPlay: false,
|
autoPlay: false,
|
||||||
rates: [1.0, 1.5, 2.0],
|
rates: [1.0, 1.5, 2.0],
|
||||||
|
jumpFrame: true,
|
||||||
|
jumpBufferDuration: 5,
|
||||||
|
frames: {
|
||||||
|
'00:10': '',
|
||||||
|
'00:20': '',
|
||||||
|
'00:30': ''
|
||||||
|
},
|
||||||
src:
|
src:
|
||||||
"https://amis.bj.bcebos.com/amis/2019-12/1577157317579/trailer_hd.mp4",
|
'https://amis.bj.bcebos.com/amis/2019-12/1577157317579/trailer_hd.mp4',
|
||||||
poster:
|
poster:
|
||||||
"https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png"
|
'https://internal-amis-res.cdn.bcebos.com/images/2019-12/1577157239810/da6376bf988c.png'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-frameLabel {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,16 @@ import {filter} from '../utils/tpl';
|
||||||
import 'video-react/dist/video-react.css';
|
import 'video-react/dist/video-react.css';
|
||||||
|
|
||||||
const str2seconds: (str: string) => number = str =>
|
const str2seconds: (str: string) => number = str =>
|
||||||
str
|
str.indexOf(':')
|
||||||
|
? str
|
||||||
.split(':')
|
.split(':')
|
||||||
.reverse()
|
.reverse()
|
||||||
.reduce(
|
.reduce(
|
||||||
(seconds, value, index) =>
|
(seconds, value, index) =>
|
||||||
seconds + (parseInt(value, 10) || 0) * Math.pow(60, index),
|
seconds + (parseInt(value, 10) || 0) * Math.pow(60, index),
|
||||||
0
|
0
|
||||||
);
|
)
|
||||||
|
: parseInt(str, 10);
|
||||||
|
|
||||||
export interface FlvSourceProps {
|
export interface FlvSourceProps {
|
||||||
src?: string;
|
src?: string;
|
||||||
|
@ -193,6 +195,7 @@ export interface VideoProps extends RendererProps {
|
||||||
columnsCount?: number;
|
columnsCount?: number;
|
||||||
isLive?: boolean;
|
isLive?: boolean;
|
||||||
jumpFrame?: boolean;
|
jumpFrame?: boolean;
|
||||||
|
jumpBufferDuration?: number;
|
||||||
src?: string;
|
src?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,18 +282,16 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jumpBufferDuration = this.props.jumpBufferDuration || 0;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
const times = this.times;
|
const times = this.times;
|
||||||
const len = times.length;
|
const len = times.length;
|
||||||
while (index < len) {
|
while (index < len - 1) {
|
||||||
if (
|
if (
|
||||||
times[index - 1] &&
|
times[index + 1] &&
|
||||||
state.currentTime <=
|
state.currentTime < times[index + 1] - jumpBufferDuration
|
||||||
times[index + 1] - (times[index + 1] - times[index]) / 2
|
|
||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
} else if (state.currentTime <= times[index]) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
@ -327,10 +328,11 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
if (!this.times || !this.player || !this.props.jumpFrame) {
|
if (!this.times || !this.player || !this.props.jumpFrame) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const jumpBufferDuration = this.props.jumpBufferDuration || 0;
|
||||||
const times = this.times;
|
const times = this.times;
|
||||||
const player = this.player;
|
const player = this.player;
|
||||||
|
|
||||||
player.seek(times[index] - (times[index] - (times[index - 1] || 0)) / 2);
|
player.seek(times[index] - jumpBufferDuration);
|
||||||
player.play();
|
player.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,10 +362,6 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
const items: Array<object> = [];
|
const items: Array<object> = [];
|
||||||
const times: Array<number> = (this.times = []);
|
const times: Array<number> = (this.times = []);
|
||||||
Object.keys(frames).forEach(time => {
|
Object.keys(frames).forEach(time => {
|
||||||
if (!frames[time]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
times.push(str2seconds(time));
|
times.push(str2seconds(time));
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
|
@ -400,8 +398,10 @@ export default class Video extends React.Component<VideoProps, VideoState> {
|
||||||
this.jumpToIndex(i * (columnsCount as number) + key)
|
this.jumpToIndex(i * (columnsCount as number) + key)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
{item.src ? (
|
||||||
<img className="w-full" alt="poster" src={item.src} />
|
<img className="w-full" alt="poster" src={item.src} />
|
||||||
<div className={`${ns}Text--center`}>{item.time}</div>
|
) : null}
|
||||||
|
<div className={`${ns}Video-frameLabel`}>{item.time}</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue