網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
一. 在react中引入
- 安裝插件
npm install –save video-react
2.在文件中引入
import {
Player,
ControlBar,
PlayToggle, // PlayToggle 播放/暫停按鈕 若需禁止加 disabled
ReplayControl, // 后退按鈕
ForwardControl, // 前進(jìn)按鈕
CurrentTimeDisplay,
TimeDivider,
PlaybackRateMenuButton, // 倍速播放選項(xiàng)
VolumeMenuButton
} from 'video-react';
import "video-react/dist/video-react.css"; // import css
二. 插件屬性
1.插件屬性地址
遇到的問(wèn)題,視頻要求自動(dòng)播放,設(shè)置autoPlay為true
。在測(cè)試時(shí)候發(fā)現(xiàn),切換Tab標(biāo)簽的時(shí)候,不會(huì)自動(dòng)播放。
解決方案:在更改數(shù)據(jù)的時(shí)候調(diào)用load方法。
this.player.subscribeToStateChange(this.handleStateChange.bind(this));
this.player.load();// 更改視頻源并重新加載視頻
部分代碼:
this.player.subscribeToStateChange(this.handleStateChange.bind(this));
this.player.load();
handleStateChange(state, prevState) {
this.setState({
player: state,
currentTime: state.currentTime,
duration:state.duration,
});
}
界面
<Player
ref={c => {
this.player = c;
}}
autoPlay='true'
playsInline ='true'
src={this.state.videoUrl}
poster="https://video-react.js.org/assets/poster.png"
>
<ControlBar autoHide={false} disableDefaultControls={source == 0?false :true}>
<ReplayControl seconds={10} order={1.1} />
<PlayToggle />
<CurrentTimeDisplay order={4.1} />
<TimeDivider order={4.2} />
<PlaybackRateMenuButton rates={[5, 2, 1.5, 1, 0.5]} order={7.1} />
<VolumeMenuButton />
</ControlBar>
</Player>
原文鏈接:https://blog.csdn.net/weixin_44433499/article/details/115194493
相關(guān)推薦
- 2022-09-15 docker倉(cāng)庫(kù)登錄及配置insecure-registries的方法_docker
- 2022-05-24 Flutter滾動(dòng)組件之SingleChildScrollView使用詳解_Android
- 2024-07-14 springboot通過(guò)CompletableFuture開(kāi)啟多線程執(zhí)行任務(wù)
- 2022-10-20 Swift初始化器與可選鏈的使用方法介紹_Swift
- 2023-03-27 Android?BroadcastReceiver傳輸機(jī)制詳解_Android
- 2024-01-09 setFirstResult ,setMaxResults
- 2022-06-01 C語(yǔ)言?超詳細(xì)介紹與實(shí)現(xiàn)線性表中的無(wú)頭單向非循環(huán)鏈表_C 語(yǔ)言
- 2022-03-15 跨域報(bào)錯(cuò):Response to preflight request doesn‘t pass ac
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支