无心Code

Come on baby!

   ::  :: 新随笔  ::  ::  :: 管理
  7 随笔 :: 1 文章 :: 0 评论 :: 1582 阅读

视频播放-video-js组件

安装

  • yarn add video.js --save
  • npm install video.js --save

代码

import React, { useEffect, useRef } from 'react';
import VideoJs from 'video.js';
// import videozhCN from 'video.js/dist/lang/zh-CN.json'
import 'video.js/dist/video-js.css';
import styles from './index.less';
type VideoType = {
video: string;
photo: string;
};
const CommonVideo = props => {
const videoRef = useRef(null);
useEffect(() => {
const player = VideoJs(
videoRef.current,
{
autoplay: false, // 自动播放
muted: false, //静音
preload: 'auto', // 预加载
controls: true, // 是否显示控制条
controlBar: {
// 设置控制条组件
// /* 设置控制条里面组件的相关属性及显示与否
currentTimeDisplay: true,
timeDivider: true,
durationDisplay: true,
remainingTimeDisplay: true, // 显示倒计时时间
fluid: true,
language: 'zh-CN', // 设置语言
volumePanel: {
inline: false,
},
// */
/* 使用children的形式可以控制每一个控件的位置,以及显示与否 */
children: [
{ name: 'playToggle' }, // 播放按钮
{ name: 'currentTimeDisplay' }, // 当前已播放时间
{ name: 'progressControl' }, // 播放进度条
{ name: 'durationDisplay' }, // 总时间
{
// 倍数播放
name: 'playbackRateMenuButton',
playbackRates: [0.5, 1, 1.5, 2, 2.5],
},
{
name: 'volumePanel', // 音量控制
inline: false, // 不使用水平方式
},
{ name: 'FullscreenToggle' }, // 全屏
],
},
},
() => {
player.src(props.video);
player.poster(props.photo);
},
);
return () => {
// player.dispose();
};
}, [props]);
return (
<video
ref={videoRef}
preload="true"
// className={styles.videoContent}
className={['video-js', 'vjs-16-9', 'vjs-big-play-centered', styles.videoContent].join(' ')}
playsInline
></video>
);
};
export default CommonVideo;
posted on   melong  阅读(473)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示