HTML5视频未显示来自Axios React数据获取视频的视频
我对视频播放器页面有问题,无法找到与视频文件关联的数据。我一直找不到404或“来自我代码的Axios代码段的未定义错误,因为这是控制台日志所在的位置。但是,数据对象也出现在控制台中,但URL仍然未定义,并且视频播放器也是
后端的代码,这是通过路由: upload.js:
const { sequelize, video } = require('../models');
router.post("/getVideo", async (req, res) => {
try {
const getvideo = await video.findOne({
"_id" : req.body.videoId
})
return res.json(getvideo)
} catch (err) {
console.log(err)
return res.status(500).json({ error: 'Something went wrong' });
}
})
Sequeilize Console似乎是功能性的,
这是前端的代码: lidetvideopage.js
const DetailVideoPage = (props) => {
let { videoId } = useParams();
const [video, setVideo] = useState([]);
const videoVariable = {
videoId: videoId
}
useEffect(() => {
axios.post('http://localhost:5000/api/upload/getVideo', videoVariable, {
headers: {
'accept': 'application/json',
},
})
.then(response => {
if (response.data.success) {
console.log(response.data.video)
setVideo(response.data.video)
console.log(response.data.success);
} else {
console.log(response.data);
alert('Failed to get video Info')
}
}).catch(error => {
console.log(error);
});
}, []);
return (
<div className="postPage" style={{ width: '100%', padding: '3rem 4em' }} >
<video style={{ width: '100%' }} src={`http://localhost:5000/${video.filePath}`} controls></video>
</div>
);
}
这是我从本地主机页面收到错误的图像: localhost console
在这里是前端的路线: 从'./组件/视图/详细信息videopage';
<Router>
<Routes>
<Route exact path='/video/:videoId' element={<DetailVideoPage />} />
</Routes>
</Router>
更新:我将问题重命名以更准确地显示问题的性质。主要问题是,即使获取了数据,也没有显示视频。
I am having issue with my video player page, not being able to find the data associated with the video file. I keep getting a 404 not found or a "undefined error coming from the axios code snippet of my code as that is where the console log for it is located. However, the object of data also appears in the console but the url remains undefined and so does the video player.
Here is the code for the backend, this is through the routing:
upload.js:
const { sequelize, video } = require('../models');
router.post("/getVideo", async (req, res) => {
try {
const getvideo = await video.findOne({
"_id" : req.body.videoId
})
return res.json(getvideo)
} catch (err) {
console.log(err)
return res.status(500).json({ error: 'Something went wrong' });
}
})
The sequeilize console appears to be functional
Here is the code for the frontend:
Detailvideopage.js
const DetailVideoPage = (props) => {
let { videoId } = useParams();
const [video, setVideo] = useState([]);
const videoVariable = {
videoId: videoId
}
useEffect(() => {
axios.post('http://localhost:5000/api/upload/getVideo', videoVariable, {
headers: {
'accept': 'application/json',
},
})
.then(response => {
if (response.data.success) {
console.log(response.data.video)
setVideo(response.data.video)
console.log(response.data.success);
} else {
console.log(response.data);
alert('Failed to get video Info')
}
}).catch(error => {
console.log(error);
});
}, []);
return (
<div className="postPage" style={{ width: '100%', padding: '3rem 4em' }} >
<video style={{ width: '100%' }} src={`http://localhost:5000/${video.filePath}`} controls></video>
</div>
);
}
Here is an image of the error I receive from my localhost page: localhost console
Here is the routes for the frontend:
import DetailVideoPage from './components/views/DetailVideoPage/DetailVideoPage';
<Router>
<Routes>
<Route exact path='/video/:videoId' element={<DetailVideoPage />} />
</Routes>
</Router>
UPDATE: I have renamed the question to more accurately display the nature of the issue. The main issue is that even though the data is fetched, the video is not being displayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案:
我已经在VC的建议和一些研究的建议下找到了解决方案,这要归功于他!
我已经为我的详细信息重构了一些代码:
}
SOLUTION:
I have found the solution with the advice of VC.One and a bit of research, much thanks to him!
I have refactored some of my code for my DetailVideoPage.JS:
}
用于测试...查看是否在页面上显示视频:
For testing... See if this shows a video on the page: