传递多个本地存储视频进行React JS弹出视频播放器
我使用AG-Grid创建了OnClick React Grid视频播放器。之后,将JSON数据传递到网格。
传递JSON数据后,我的Ag-Grid看起来像
现在,我只通过了一个本地存储视频来反应视频播放器(Play play Buter) )
import myData from "../video.mp4"
....
....
<DialogContent>
<iframe width="560" height="315" src={myData} allowFullScreen></iframe>
</DialogContent>
src = {mydata}在我的本地存储中表示 video.mp4 ,现在如何使用多个视频通过json文件来反应视频播放器
我的json文件结构:
{
"users": [
{
"id": 1,
"name": "Hari",
"email": "[email protected]",
"phone": "9876543210",
"dob": "/home/fraction/Music/agGrid-crudOperation/src/video1.mp4"
},
{
"name": "Hari",
"email": "[email protected]",
"phone": "9876543210",
"dob": "/home/fraction/Music/agGrid-crudOperation/src/video2.mp4",
"id": 5
}
]
}
我尝试通过视频url使用地图方法,但它不起作用。如何通过React JS中的JSON文件传递多个视频,
以获取更多代码详细信息,请参阅在这里
任何建议和建议回答事先感谢您。
i created onclick react grid video player using ag-grid. after that passing json data to grid.
after passing json data my ag-grid look like
Now i passed only one local storage video to react video player(Play button )
import myData from "../video.mp4"
....
....
<DialogContent>
<iframe width="560" height="315" src={myData} allowFullScreen></iframe>
</DialogContent>
src={myData} is represent video.mp4 in my local storage , Now how to i pass multiple videos to react video player using json file
my json file structure like this :
{
"users": [
{
"id": 1,
"name": "Hari",
"email": "[email protected]",
"phone": "9876543210",
"dob": "/home/fraction/Music/agGrid-crudOperation/src/video1.mp4"
},
{
"name": "Hari",
"email": "[email protected]",
"phone": "9876543210",
"dob": "/home/fraction/Music/agGrid-crudOperation/src/video2.mp4",
"id": 5
}
]
}
i tried to pass video url using map method but its didnt work me. how to pass multiple videos through json file in react js
for more code details refer here
Any suggestion and answer are heartly appreciated thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
猜测这里的本地存储是指视频所在的存储库文件夹。
它不起作用的主要原因是因为您的前端没有提供视频。
我建议进行服务器端设置并为每个视频提供一个网址。然后只需在前端中引用该 url,而不是在前端中嵌入整个 mp4。
import myData from "../video.mp4"
之所以有效,是因为 webpack 在编译期间只是将整个视频二进制文件嵌入到前端 JavaScript 中。对于多个视频的情况,它不起作用的原因很简单,它们在您的 JavaScript 中不是
require
或import
,因此它们没有嵌入到您的前端代码中。如果您确实想让前端读取本地文件,您可以使用文件系统访问 API 并查看此参考,这是 API 的完整指南。
如果您想使用
map()
,您可以将 json 更改为类似这样的内容,其中 dob 作为您的视频网址。然后在您的 iframe 中,使用视频的 dob url
Guessing the local storage meant here is the repository folder where videos are present.
The main reason for why it does not work is because videos are not served for your frontend.
I would suggest having a server side setup and serve each video with an url. Then simply refer to that url in your frontend, rather than embedding the whole mp4 within your frontend.
The
import myData from "../video.mp4"
which works because of webpack simply embedded the whole video binary within your frontend javascript during compilation.For multiple videos case, the reason why it does not work is simply they are not
require
orimport
in your javascript, so they are not embedded to your frontend code.If you really want to have frontend reading your local files, you may use
File System Access API
and take a look at this reference, and this is full guide of the API.If you want to use the
map()
, you may change the json to something like this, with dob as your video url.Then in your iframe, use the dob url for the video