javascript - 使用 React 使 YouTube 视频自动播放
问题描述
我正在尝试使用 react 让我的视频自动播放。添加autoplay=1
为参数不起作用。有什么建议吗?
这是我的代码。
<div
className="video mt-5"
style={{
position: "relative",
paddingBottom: "56.25%" /* 16:9 */,
paddingTop: 25,
height: 0
}}
>
<iframe
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%"
}}
src={'https://www.youtube.com/embed/hEnr6Ewpu_U?'}
frameBorder="0"
/>
</div>
解决方案
我不会使用<iframe>
因为当你去 Youtube 时你仍然需要点击才能播放。我会使用一个名为 react-player 的库
import ReactPlayer from "react-player";
<ReactPlayer
url={props.url}
playing={true}
width={props.width}
height={props.height}
/>
它会自动播放:)
推荐阅读
- interop - FHIR 互操作性平台选择
- c++ - Qt5中如何比较两个中文字符串?
- java - 关于使用 UDP 将 mp3 文件从客户端上传到服务器
- c# - 如何通过单击按钮启动倒数计时器事件?
- ios - 配置文件即将过期
- database - 由于 Oracle DB 从 12c 升级到 19c,对现有 SQL、PL/SQL 脚本和数据模型有何影响?
- python - 错误/警告 *** MULE MSG QUEUE 已满:缓冲区大小 212992 字节(您可以使用 --mule-msg-size 调整它)***
- rust - 如何在 rust 中为泛型结构指定泛型特征
- python-2.7 - Python V2 EOL 之后在 Pypi 上访问 Python V2 包
- php - 对于每个问题 Laravel Blade