播放按钮onclick视频播放器中的react js
使用fetch
调用API并在控制台中获取响应,然后将值分配给表标头。 之后,在React Js中创建一个按钮。每个按钮都有一个视频URL,该视频URL来自API响应
API响应:
Camera_Number:"Camera_1"
Group_Name: "Group_1"
Video_Name: "http://localhost:4000/video/0"
Camera_Number:"Camera_2"
Group_Name: "Group_2"
Video_Name: "http://localhost:4000/video/1"
我将此响应存储在usestate
中,然后将此usestate响应传递给视频播放器源上方代码
const actionButton = (params) => {
setVideoName(params.videoName); // I am assuming but need to update videoName here
setOpen(true);
};
headerName: "Actions",
field: "Video_Name",
cellRendererFramework: (params) => (
<div>
<Button
variant="contained"
onClick={() => actionButton(params)}
>
Play
</Button>
</div>
上面的code show dission_name到action> actions
标题然后创建一个按钮。当我单击一个按钮时,所有视频都会在一个窗口中打开并播放所有视频。但是我想要它,以便只有点击的某些视频才能显示。
<DialogContent>
{response.map(({ Video_Name }) => (
<iframe
width="420"
height="315"
title="videos"
src={Video_Name}
/>
))}
</DialogContent>
如何使用React-Hooks解决此问题。
有关更多详细信息和代码参考
如何为视频和视频和视频创建索引将视频传递给视频播放器来源。当我单击该按钮时,单击某些视频将显示。
谢谢
call API using fetch
and get response in console and assign values to table header.
after that creating one button in react js. Each button have one video URL which is got from API response
API response:
Camera_Number:"Camera_1"
Group_Name: "Group_1"
Video_Name: "http://localhost:4000/video/0"
Camera_Number:"Camera_2"
Group_Name: "Group_2"
Video_Name: "http://localhost:4000/video/1"
I stored this response in useState
and pass this usestate response to video player source
const actionButton = (params) => {
setVideoName(params.videoName); // I am assuming but need to update videoName here
setOpen(true);
};
headerName: "Actions",
field: "Video_Name",
cellRendererFramework: (params) => (
<div>
<Button
variant="contained"
onClick={() => actionButton(params)}
>
Play
</Button>
</div>
Above code shows assign video_name to Actions
header then I created one button. when I click one button, all of the videos open in one window and play all videos. But I want it so that only that certain video that was clicked would show.
<DialogContent>
{response.map(({ Video_Name }) => (
<iframe
width="420"
height="315"
title="videos"
src={Video_Name}
/>
))}
</DialogContent>
How to resolve this issue using react-hooks.
for more details and code reference
how to create index for video and pass videos to video player source. when i click that button certain video that was clicked would show.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应
状态对象包含完整的API响应。&lt; dialogContent&gt;
映射此&amp;创建多个iframe 元素。我们不需要映射&amp;创建多个iFrames-而不是根据单击行的视频名称创建对话框内容。
结果是行视频URL。您现在可以使用它播放实际的视频。
The
response
state object contains the complete API response.<DialogContent>
maps over this & create multiple iframe elements. We don't need to map & create multiple iframes -Instead create dialog content based on name of the video where row was clicked.
Output - Click on any row's play button. Result is that rows video url. You can now use this to play the actual video.