更改.net中HTML5视频标签中的src

发布于 2024-11-11 13:31:08 字数 179 浏览 2 评论 0原文

我想知道是否有一种方法可以轻松地从代码隐藏更改 HTML5 中视频标签中的 src?

我现在的解决方案是使用不同的 WebUserControl,并在单击按钮时将它们放置在 PlaceHolder 中,但是这种快速会导致很多控件。

必须有更好的方法。

也许就像在 src 中放置标签、绑定某种类型

Im wondering if there is a way to easily change the src in the video tag in HTML5 from codebehind?

my solution now is to use different WebUserControl's and place them in a PlaceHolder when their button is clicked, but this fast leads to a lot of control's.

There has to be a better way.

maybe like placing a label, bind of some sort in the src

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

霊感 2024-11-18 13:31:08

只要添加 runat="server",任何标签都可以在代码隐藏中添加属性,所以是的,有。

在 .aspx 页面中:

<video id="videoTag" runat="server" />

代码隐藏:

videoTag.Attributes["src"] = "bob";

或者您可以编写自己的 webcontrol。这需要更多的工作和对 ASP.NET 的理解,但如果您要经常使用它,那么这是值得的。

如果您使用 ASP.Net MVC,据我所知,他们已经在 ASP.Net MVC 3 中发布了对 HTML5 的支持。

Any tag can have attributes added to it in code-behind as long as you add a runat="server", so yes, there is.

in .aspx page:

<video id="videoTag" runat="server" />

code-behind:

videoTag.Attributes["src"] = "bob";

Alternatively you can write your own webcontrol. This involves more work and understanding of asp.net, but will be worth it if you're going to use this a lot.

And if you're using ASP.Net MVC, they've already released support for HTML5 in ASP.Net MVC 3 as I understand it.

最终幸福 2024-11-18 13:31:08

通过将其放在 aspx 页面中

<asp:PlaceHolder ID="VidModule" runat="server"></asp:PlaceHolder>

并将其放在代码隐藏中来解决它

    //Video relevant int's
int width {get; set;}
int height { get; set; }


//Video relevant text's
string overskrift { get; set; }
string poster { get; set; }
string titleimg { get; set; }
string ogv { get; set; }
string mp4 { get; set; }
string webm { get; set; }
string reso { get; set; }
string res { get; set; }


protected void Page_Load(object sender, EventArgs e)
{



}

//low 240i resolution player LowD
protected void low240i_Click(object sender, EventArgs e)
{
    height = 480;
    width = 640;
    reso = "240i";
    if (reso == "240i")
        res = "240i/";
    else if (reso == "240p")
        res = "240p/";
    else if (reso == "480p")
        res = "480p/";
    else if (reso == "720p")
        res = "720p/";

    int Data = Convert.ToInt32(Request.QueryString["id"]);
    VideoDataContext db = new VideoDataContext();

    var fetch = from list in db.VideoDBs
                where
                list.VidID == Data
                select list;

    foreach (var list in fetch)
    {
        overskrift = "\"" + list.Name + "\"";
        poster = "\"" + list.IMGAddr + "\"";
        titleimg = "\"" + list.IMGAddr + "\"";
        if (list.mp4 == true)
            mp4 = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".mp4" + "\"";
        else
            mp4 = null;
        if (list.ogv == true)
            ogv = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".ogv" + "\"";
        else
            ogv = null;
        if (list.webm == true)
            webm = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".webm" + "\"";
        else
            webm = null;
    }

    Panel1.Controls.Add(new LiteralControl("<div class=player ><br />"));
    Panel1.Controls.Add(new LiteralControl("<h3>" + overskrift + " in " + reso + "</h3><br /><br />"));
    Panel1.Controls.Add(new LiteralControl("<video controls=controls id=video width=" + "\"" + width + "\"" + " height=" + "\"" + height + "\"" + " poster=" + poster + " preload=auto >"));
    Panel1.Controls.Add(new LiteralControl("<source src=" + mp4 + " type=\"video/mp4; codecs=avc1.42E01E, mp4a.40.2\" title=" + titleimg + " />"));
    Panel1.Controls.Add(new LiteralControl("<source src=" + webm + " type=\"video/webm; codecs=vp8, vorbis\" title=" + titleimg + " />"));
    Panel1.Controls.Add(new LiteralControl("<source src=" + ogv + " type=\"video/ogg; codecs=theora, vorbis\" title=" + titleimg + " />"));
    Panel1.Controls.Add(new LiteralControl("Your browser does not support the video tag."));
    Panel1.Controls.Add(new LiteralControl("</video></div>"));
}

solved it by placing this in the aspx page

<asp:PlaceHolder ID="VidModule" runat="server"></asp:PlaceHolder>

and this in the codebehind

    //Video relevant int's
int width {get; set;}
int height { get; set; }


//Video relevant text's
string overskrift { get; set; }
string poster { get; set; }
string titleimg { get; set; }
string ogv { get; set; }
string mp4 { get; set; }
string webm { get; set; }
string reso { get; set; }
string res { get; set; }


protected void Page_Load(object sender, EventArgs e)
{



}

//low 240i resolution player LowD
protected void low240i_Click(object sender, EventArgs e)
{
    height = 480;
    width = 640;
    reso = "240i";
    if (reso == "240i")
        res = "240i/";
    else if (reso == "240p")
        res = "240p/";
    else if (reso == "480p")
        res = "480p/";
    else if (reso == "720p")
        res = "720p/";

    int Data = Convert.ToInt32(Request.QueryString["id"]);
    VideoDataContext db = new VideoDataContext();

    var fetch = from list in db.VideoDBs
                where
                list.VidID == Data
                select list;

    foreach (var list in fetch)
    {
        overskrift = "\"" + list.Name + "\"";
        poster = "\"" + list.IMGAddr + "\"";
        titleimg = "\"" + list.IMGAddr + "\"";
        if (list.mp4 == true)
            mp4 = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".mp4" + "\"";
        else
            mp4 = null;
        if (list.ogv == true)
            ogv = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".ogv" + "\"";
        else
            ogv = null;
        if (list.webm == true)
            webm = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".webm" + "\"";
        else
            webm = null;
    }

    Panel1.Controls.Add(new LiteralControl("<div class=player ><br />"));
    Panel1.Controls.Add(new LiteralControl("<h3>" + overskrift + " in " + reso + "</h3><br /><br />"));
    Panel1.Controls.Add(new LiteralControl("<video controls=controls id=video width=" + "\"" + width + "\"" + " height=" + "\"" + height + "\"" + " poster=" + poster + " preload=auto >"));
    Panel1.Controls.Add(new LiteralControl("<source src=" + mp4 + " type=\"video/mp4; codecs=avc1.42E01E, mp4a.40.2\" title=" + titleimg + " />"));
    Panel1.Controls.Add(new LiteralControl("<source src=" + webm + " type=\"video/webm; codecs=vp8, vorbis\" title=" + titleimg + " />"));
    Panel1.Controls.Add(new LiteralControl("<source src=" + ogv + " type=\"video/ogg; codecs=theora, vorbis\" title=" + titleimg + " />"));
    Panel1.Controls.Add(new LiteralControl("Your browser does not support the video tag."));
    Panel1.Controls.Add(new LiteralControl("</video></div>"));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文