简体   繁体   中英

Bind videos from folder in asp.net using datalist

<asp:DataList ID="dtlVideos" runat="server">
    <ItemTemplate>
        <table>
            <tr>
                <td>
                     <video controls="controls"  width="200" height="200" src='<%# Eval ("Name","videos/{0}") %>'>"/>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

public partial class videos : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataList();
        }
    }
    protected void BindDataList()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath("~/videos"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        dtlVideos.DataSource = listItems;
        dtlVideos .DataBind(); 
    }
}

unable to play videos in chrome or browsers and mozilla is only supporting in .mp4 format not other formats i want to make this app support all formats

<video controls="controls"  width="200" height="200" src='<%# Eval ("Name","videos/{0}") %>'>"/>

Thil line should be

<video controls="controls"  width="200" height="200" src='<%# Eval ("Name","videos/{0}") %>'></video>

or

<video controls="controls"  width="200" height="200" src='<%# Eval ("Name","videos/{0}") %>'/>

Media formats supported by the HTML audio and video elements

To make an HTML5 video, which works in the newest versions of all major browsers, you can serve your video in both WebM format and MPEG H.264 AAC format, using the source element like this:

<video controls>
  <source src="somevideo.webm" type="video/webm">
  <source src="somevideo.mp4" type="video/mp4">
  I'm sorry; your browser doesn't support HTML5 video in WebM with VP8 or MP4 with H.264.
  <!-- You can embed a Flash player here, to play your mp4 video in older browsers -->
</video>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM