reactjs - 按钮禁用,直到 youtube 视频结束 - 反应打字稿
问题描述
我对打字稿做出反应还很陌生。我希望我的视频完成,然后才能使用继续按钮。我找到了如何在 javascript 中执行此操作,但由于某种原因,它不适用于 react typescript。到目前为止,这是我的代码:
import { Link } from "react-router-dom";
import Container from 'react-bootstrap/Container';
function timeout(delay: number) {
return new Promise(res => setTimeout(res, delay));
}
export function Video() {
return (
<Container className="p-3">
<div className="alert alert-info" role="alert">
<h4 className="alert-heading"></h4>
<p style={{ textAlign: "center" }}>
<big> <b> Please watch the video </b> </big>
<br />
</p>
<iframe
title={"video"}
width={"560"}
height={"315"}
style={{
marginLeft: "auto",
marginRight: "auto",
marginBottom: "40px",
display: "block",
}}
src="https://www.youtube.com/embed/iw5lP63fUxY?autoplay=1&controls=0"
frameBorder={"0"}
allow={
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
}
allowFullScreen
/>
<p style={{ textAlign: "center" }}>
<Link to="/A">
<button type="button" className="btn btn-info">
Continue
</button>
</Link>
</p>
</div>
</Container>
);
}
解决方案
你试过这个吗? https://www.npmjs.com/package/react-player
特别是“onBufferEnd”回调。
<ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' onBufferEnd={()=>setCanContinue(true)} />
和“继续”按钮:
const [canContinue,setCanContinue] = useState(false)
<button type="button" {canContinue ? "" : "disabled"} className="btn btn-info">
推荐阅读
- apache-spark - 如何在不分叉/修改 Spark 本身的情况下创建自定义 Spark-Native 函数
- c# - 代码中的字符串与文件中的字符串有什么区别
- reactjs - 我在 reactjs 中创建表单时遇到问题
- google-apps-script - 在 Google 表格插件中进行 DNS 查找时获取“名称服务器拒绝查询(蹩脚委托?)”
- ios - 在 SwiftUI 中有条件地更改 NavigationLink 目标
- c# - 如何在c#中同时执行一个方法?
- node.js - 设置限制电子邮件发送计数
- javascript - MondoDB Atlas 几分钟后卡住了
- sql-server - 使用 pyspark 对 SQL Server JDBC 使用 Windows 身份验证
- java - Java 服务器的 GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS?