網站首頁 編程語言 正文
一. 在react中引入
- 安裝插件
npm install –save video-react
2.在文件中引入
import {
Player,
ControlBar,
PlayToggle, // PlayToggle 播放/暫停按鈕 若需禁止加 disabled
ReplayControl, // 后退按鈕
ForwardControl, // 前進按鈕
CurrentTimeDisplay,
TimeDivider,
PlaybackRateMenuButton, // 倍速播放選項
VolumeMenuButton
} from 'video-react';
import "video-react/dist/video-react.css"; // import css
二. 插件屬性
1.插件屬性地址
遇到的問題,視頻要求自動播放,設置autoPlay為true
。在測試時候發現,切換Tab標簽的時候,不會自動播放。
解決方案:在更改數據的時候調用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
相關推薦
- 2022-06-14 一文帶你搞懂Numpy中的深拷貝和淺拷貝_python
- 2022-02-27 Web server failed to start. Port 8989 was already
- 2022-09-06 C語言常見排序算法之交換排序(冒泡排序,快速排序)_C 語言
- 2022-09-05 Spark Rdd之mapToPair,flatMapToPair
- 2022-05-04 Spring.Net框架簡介_實用技巧
- 2023-01-30 Android?Https證書過期的兩種解決方案_Android
- 2022-11-07 C語言內存函數?memcpy,memmove?,memcmp_C 語言
- 2022-04-20 淺談C語言的變量和常量_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支