视频播放-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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示