admin管理员组文章数量:1310228
I am trying to put video background on my site but when I put video tag to my react script it start endlessly loading on Firefox and when I try it on chrome it shows the video at 0 seconds I've tried .mp4
and .mov
formats without success.
import React, { Component } from "react";
import "./App.css";
import LogginScreen from "./ponents2/LogginScreen";
class App extends Component {
render() {
return (
<div>
<LogginScreen></LogginScreen>
<video controls autoPlay loop muted>
<source src="hd1992.mov" type="video/mov"></source>
</video>
</div>
);
}
}
export default App;
I am trying to put video background on my site but when I put video tag to my react script it start endlessly loading on Firefox and when I try it on chrome it shows the video at 0 seconds I've tried .mp4
and .mov
formats without success.
import React, { Component } from "react";
import "./App.css";
import LogginScreen from "./ponents2/LogginScreen";
class App extends Component {
render() {
return (
<div>
<LogginScreen></LogginScreen>
<video controls autoPlay loop muted>
<source src="hd1992.mov" type="video/mov"></source>
</video>
</div>
);
}
}
export default App;
Share
Improve this question
edited Jan 10, 2020 at 21:36
Michalis Garganourakis
2,9301 gold badge13 silver badges25 bronze badges
asked Jan 9, 2020 at 19:26
Tomáš VránaTomáš Vrána
1241 gold badge1 silver badge8 bronze badges
8
- Are there any errors shown in the console for both firefox and chrome? If yes please edit your post and add them in there so we can help you better. – Kevin Hernandez Commented Jan 9, 2020 at 19:33
- no there is no errors in console or in web inspect tools – Tomáš Vrána Commented Jan 9, 2020 at 19:39
- 1 i tryed play video linked from YouTube and everything working correctly when i use iframe but i need it to be a backgraund so this is pointless. – Tomáš Vrána Commented Jan 9, 2020 at 20:15
-
i do not know why but when I put this code in JavaScript file it work
<video autoplay muted loop name="media"> <source src="http://www.html5rocks./en/tutorials/video/basics/devstories.mp4" type="video/mp4" ></source> </video>
– Tomáš Vrána Commented Jan 9, 2020 at 20:44 - it seems like the only way how i can play video is by linking it – Tomáš Vrána Commented Jan 9, 2020 at 21:11
1 Answer
Reset to default 6This is related both to the video file type .mov
and the way you import your video.
Try to change your type attribute to type="video/mp4"
even though it's a .mov
and import your video like below:
import React, { Component } from "react";
import "./App.css";
import LogginScreen from "./ponents2/LogginScreen";
import myVideo from "./hd1992.mov";
class App extends Component {
render() {
return (
<div>
<LogginScreen></LogginScreen>
<video controls autoPlay loop muted>
<source src={myVideo} type="video/mp4"></source>
</video>
</div>
);
}
}
export default App;
Here is a working example.
I hope this solves your issue.
本文标签: javascriptReact video element is not working properlyStack Overflow
版权声明:本文标题:javascript - React video element is not working properly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741839075a2400389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论