如何使用asp.net(c#)将视频文件插入和检索到数据库,然后在aspx上播放? [英] How to Insert and retrieve video files into database using asp.net (c#)and then play it on aspx ?

查看:85
本文介绍了如何使用asp.net(c#)将视频文件插入和检索到数据库,然后在aspx上播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用asp.net(c#)将视频文件插入和检索到数据库然后在.aspx页面上播放?

如果有人知道那么请发给我代码。或建议一些想法。

谢谢。

解决方案

更好地将文件存储在硬盘上并在数据库中存储路径和文件名。不建议在电影的数据库中的1个字段中使用1.4GB。


使用Sql的简单插入检索方法。只需将视频文件名保存在数据库中即可。



为了在服务器上保存视频,试试这个...

 字符串 guid = Guid.NewGuid()。ToString(); 
字符串 path = Server.MapPath( 〜/ Vids /)+ guid;
String fn = FileUpload1.FileName;
// 将此文件名保存在数据库中//
String filename = guid + fn.Substring(fn.LastIndexOf(' 。'< /跨度>));
// 这将文件保存在服务器Vids文件夹上//确保它首先存在
FileUpload1.PostedFile.SaveAs(path);





完成所有这些后你必须播放视频。为此,使用silverlight mediaplayer(rad)或更简单的选项使用embed关键字作为...



< embed src =path autoplay =falseshowcontrols =true>< / embed> 







关于嵌入的更多信息... HTML EMBED - HTML代码教程 [ ^ ]



希望有帮助......


您可以使用Flowplayer播放检索视频:







 <   html     xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = SER ver >
< 标题 > < /标题 >
< style type = text / css >
body
{
font - 家庭:Arial;
字体大小:10pt;
}
< / style >
< / head >
< body >
< 表格 id = form1 runat = server >
< asp:FileUpload ID = FileUpload1 runat = server / >
< asp:按钮 ID = btnUpload runat = 服务器 文字 = 上传 OnClick = btnUpload_Click / >
< hr / >
< asp:DataList ID = DataList1 可见 = true runat = server < span class =code-attribute> AutoGenerateColumns = false

RepeatColumns = 2 CellSpacing = 5 >
< ItemTemplate >
< u >
<% #Eval( 名称%> < / u >
< hr / >
< a class = 播放器 style = height:300px;宽度:300px; display:block href =' <% #Eval( Id FileCS.ashx?Id = {0} %> ' >
< / a >
< span class =code-keyword>< / ItemTemplate >
< / asp:DataList >
< script src = FlowPlayer / flowplayer-3.2.12.min.js type = text / javascript > < / script >
< script 类型 = text / javascript > ;
flowplayer(a.player,FlowPlayer / flowplayer-3.2.16.swf,{
plugins:{
pseudo:{url:FlowPlayer / flowplayer .pseudostreaming-3.2.12.swf}
},
clip:{provider:'pseudo',autoPlay:false},
});
< / script >
< / form >
< / body >
< / html >


How to Insert and retrieve video files into database using asp.net (c#)and then play it on .aspx page ?
if someine know then please send me code. or suggest some idea.
thanks.

解决方案

better to store the files on a harddrive and store path and filename in the database. 1.4GB in 1 field in a db for a movie is not advisable.


Use simple Insert Retrieval methods of Sql. Just save the filename of video in database.

For saving video on server try this...

String guid = Guid.NewGuid().ToString();
String path = Server.MapPath("~/Vids/") + guid;
String fn = FileUpload1.FileName;
//Save this filename in database//
String filename = guid + fn.Substring(fn.LastIndexOf('.'));
//this saves file on server Vids folder// make sure it exists first
FileUpload1.PostedFile.SaveAs(path);



After all this you have to play video. For that either use silverlight mediaplayer(rad) or the easier option use the embed keyword as...

<embed src="path" autoplay="false" showcontrols="true"></embed> 




more info on embed ...HTML EMBED - HTML Code Tutorial[^]

Hope it helps...


You can Use Flowplayer for playing the retrieved video:



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
    <hr />
    <asp:DataList ID="DataList1" Visible="true" runat="server" AutoGenerateColumns="false"

        RepeatColumns="2" CellSpacing="5">
        <ItemTemplate>
            <u>
                <%# Eval("Name") %></u>
            <hr />
            <a class="player" style="height: 300px; width: 300px; display: block" href='<%# Eval("Id", "FileCS.ashx?Id={0}") %>'>
            </a>
        </ItemTemplate>
    </asp:DataList>
    <script src="FlowPlayer/flowplayer-3.2.12.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        flowplayer("a.player", "FlowPlayer/flowplayer-3.2.16.swf", {
            plugins: {
                pseudo: { url: "FlowPlayer/flowplayer.pseudostreaming-3.2.12.swf" }
            },
            clip: { provider: 'pseudo', autoPlay: false},
        });
    </script>
    </form>
</body>
</html>


这篇关于如何使用asp.net(c#)将视频文件插入和检索到数据库,然后在aspx上播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆