播放按钮onclick视频播放器中的react js

发布于 2025-02-03 13:10:35 字数 1667 浏览 3 评论 0原文

使用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解决此问题。

有关更多详细信息和代码参考

https://github.com/iamharry-dev/modal_popup

如何为视频和视频和视频创建索引将视频传递给视频播放器来源。当我单击该按钮时,单击某些视频将显示。

谢谢

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

https://github.com/iamharry-dev/modal_popup

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2025-02-10 13:10:35

响应状态对象包含完整的API响应。 &lt; dialogContent&gt;映射此&amp;创建多个iframe 元素。我们不需要映射&amp;创建多个iFrames-

<DialogContent>
  {response.map(({ Video_Name }) => (
...

而不是根据单击行的视频名称创建对话框内容。

const [videoName, setVideoName] = useState("");

function onCellClicked(params) {
    // maps to colId: "action" in columnDefs,
    if (params.column.colId === "action") {
      // set videoName for the row
      setVideoName(params.node.data.Video_Name);
      setOpen(true);
    }
}

// grid config
<AgGridReact
  ...
  rowData={response}
  onCellClicked={onCellClicked}>
</AgGridReact>

// access videoName in dialog content
<DialogContent>
 <div>{videoName}</div>
</DialogContent>

​结果是行视频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 -

<DialogContent>
  {response.map(({ Video_Name }) => (
...

Instead create dialog content based on name of the video where row was clicked.

const [videoName, setVideoName] = useState("");

function onCellClicked(params) {
    // maps to colId: "action" in columnDefs,
    if (params.column.colId === "action") {
      // set videoName for the row
      setVideoName(params.node.data.Video_Name);
      setOpen(true);
    }
}

// grid config
<AgGridReact
  ...
  rowData={response}
  onCellClicked={onCellClicked}>
</AgGridReact>

// access videoName in dialog content
<DialogContent>
 <div>{videoName}</div>
</DialogContent>

Edit reverent-zhukovsky-gt4mln

Output - Click on any row's play button. Result is that rows video url. You can now use this to play the actual video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文