如何使用TypeScript在React的背景中自动播放视频?
我非常陌生,可以在我的一个组件中添加自动播放视频,但由于某种原因,如果大家都可以建议如何做同样的事情,它不会发挥作用。
我尝试使用,
导出const videobg =()=> { 返回( ) };
导出const videobg =()=> { 返回( 视频 ) };
但是没有什么可用,请帮助我
I am very new to react and possibly trying to add a autoplay video in one of my components but for some reason it doesn't play if you all can possibly suggest how to do the same.
I have tried using,
export const VideoBg = () =>{
return(
)
};
export const VideoBg = () =>{
return(
Video
)
};
but nothing works please help me out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用React Refs来控制您的视频元素。
在此示例中,我正在使用按钮控制它们,但是您也可以从任何地方调用这些功能。如果您希望在组件渲染时播放它,则将函数调用包装在
useffect
挂钩中。codesandbox:
https://codesandbox.io/s/graciacy-mccarthy-benex4
You can use React refs to control your video elements.
In this example I'm controlling them using buttons, but you can also call these functions from anywhere. If you wanted it to play when the component renders, you'd wrap the function call in a
useEffect
hook.CodeSandbox:
https://codesandbox.io/s/gracious-mccarthy-benex4