gpt4 book ai didi

javascript - 使用 React 让 YouTube 视频自动播放

转载 作者:行者123 更新时间:2023-11-28 05:10:20 27 4
gpt4 key购买 nike

我正在尝试使用 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}
/>

它会自动播放:)

关于javascript - 使用 React 让 YouTube 视频自动播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58027168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com