在运行时更改 html 视频控件源
本文关键字:视频 控件 html 运行时 | 更新日期: 2023-09-27 18:34:15
我需要用新的源更新位于我的页面上的html视频控件,这是我的代码,它运行4个ID为video01,video02..video04的控件,并应使用目录fileDir中找到的视频文件填充它们的源。
String[] videoFiles = Directory.GetFiles(fileDir);
int i = 0;
HtmlVideo vid;
foreach (string f in videoFiles)
{
i++;
vid = (HtmlVideo)FindControl("video0" + i.ToString());
vid.Src = "f";
}
而在 aspx 页面上,我有 4 个此类控件
<div style="width:100%; height:330px">
<div style="width:330px; float:left; height:321px; border:thick; border: thick none black;">
<asp:Label runat="server" ID="lb_vid1">Slave 01 - No input</asp:Label>
<video runat="server" id="video01" width="320" height="240" controls="controls">
<source src="yourmovie.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
</div>
代码不起作用。
你的代码不应该读:
String[] videoFiles = Directory.GetFiles(fileDir);
int i = 0;
HtmlVideo vid;
foreach (string f in videoFiles)
{
i++;
vid = (HtmlVideo)FindControl("video0" + i.ToString());
vid.Src = f;
}
"f"表示源是网址"f"。您需要包含源f
。
如果这不是问题所在,请查看 c# 代码是否真的可以找到控件。