Reputation: 198
I need some help to handle local video files in reactjs... can't resolve ./assets/video.mp4 error... tried every possible direction..
the idea behind this is to make a full screen video like https://www.w3schools.com/howto/howto_css_fullscreen_video.asp but with Reactjs.
video.js
import React from 'react';
class Video extends React.Component {
render(){
return(
<div className="myVideo">
<video controls autostart autoPlay src={this.props.src} type={this.props.type}/>
</div>
)
}
}
export default Video;
index.js
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import Video from './video';
import Robin from './assets/Robin.mp4'
const VIDEO = {
src:Robin,
type:'video/mp4'
};
class App extends Component {
constructor(props){
super(props)
this.state = {
src: VIDEO.src,
type:VIDEO.type
}
}
render(){
return(
<div>
<Video src={this.state.src} type={this.state.type}/>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'));
console error:
./src/index.js Module not found: Can't resolve './assets/*.mp4' in 'C:\Users\sanjs\Desktop\landing-video\src'
Upvotes: 11
Views: 32792
Reputation: 4625
custom.d.ts
in your src directorydeclare module '*.mp4' {
const src: string;
export default src;
}
That should work!
Upvotes: 20
Reputation: 198
solved! the problem was that the filename 'Robin .mp4' and I imported as ''Robin.mp4" so I changed de filename to 'Robin.mp4' and that's it.
Upvotes: 2
Reputation: 758
Maybe you have some spelling mistake here is a code for import local video and it just works fine
import React from "react";
import "./App.css";
import Video from "./video.mp4";
function App() {
return (
<div className="App">
<video controls autostart autoPlay src={Video} type="video/mp4" />
</div>
);
}
export default App;
I imported my video file at the same directory of app.js. Maybe this will help you.
Upvotes: 7