Asp.net FMS開發視頻網站

來源:互聯網
上載者:User

開發步驟:

1。下載FMS http://blogs.ugidotnet.org/kfra/archive/2006/10/04/50003.aspx,安裝配置。

2。使用flash製作FMS視頻採集的控制項。

3。aspx頁面嵌入FMS採集控制項,運行採集資料上傳到FMS伺服器,修改資料庫的視頻檔案存放地址。

4。頁面嵌入Flash播放控制項,加入FLV處理流代碼:

1using System;
2using System.IO;
3using System.Web;
4
5
6/**//// <summary>
7/// Summary description for FLVStreaming
8/// </summary>
9public class FLVStreaming : IHttpHandler
10{
11  private static readonly byte[] _flvheader = HexToByte("464C5601010000000900000009"); //"FLV\x1\x1\0\0\0\x9\0\0\0\x9"
12
13  public FLVStreaming()
14  {
15  }
16
17  public void ProcessRequest(HttpContext context)
18  {
19    try
20    {
21      int pos;
22      int length;
23
24      // Check start parameter if present
25      string filename = Path.GetFileName(context.Request.FilePath);
26
27      using (FileStream fs = new FileStream(context.Server.MapPath(filename), FileMode.Open, FileAccess.Read, FileShare.Read))
28      {
29        string qs = context.Request.Params["start"];
30
31        if (string.IsNullOrEmpty(qs))
32        {
33          pos = 0;
34          length = Convert.ToInt32(fs.Length);
35        }
36        else
37        {
38          pos = Convert.ToInt32(qs);
39          length = Convert.ToInt32(fs.Length - pos) + _flvheader.Length;
40        }
41
42        // Add HTTP header stuff: cache, content type and length
43        context.Response.Cache.SetCacheability(HttpCacheability.Public);
44        context.Response.Cache.SetLastModified(DateTime.Now);
45
46        context.Response.AppendHeader("Content-Type", "video/x-flv");
47        context.Response.AppendHeader("Content-Length", length.ToString());
48
49        // Append FLV header when sending partial file
50        if (pos > 0)
51        {
52          context.Response.OutputStream.Write(_flvheader, 0, _flvheader.Length);
53          fs.Position = pos;
54        }
55
56        // Read buffer and write stream to the response stream
57        const int buffersize = 16384;
58        byte[] buffer = new byte[buffersize];
59        
60        int count = fs.Read(buffer, 0, buffersize);
61        while (count > 0)
62        {
63          if (context.Response.IsClientConnected)
64          {
65            context.Response.OutputStream.Write(buffer, 0, count);
66            count = fs.Read(buffer, 0, buffersize);
67          }
68          else
69          {
70            count = -1;
71          }
72        }
73      }
74    }
75    catch (Exception ex)
76    {
77      System.Diagnostics.Debug.WriteLine(ex.ToString());
78    }
79  }
80
81  public bool IsReusable
82  {
83    get { return true; }
84  }
85
86  private static byte[] HexToByte(string hexString)
87  {
88    byte[] returnBytes = new byte[hexString.Length / 2];
89    for (int i = 0; i < returnBytes.Length; i++)
90      returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
91    return returnBytes;
92  }
93
94}
95

修改設定檔,運行頁面即可調出視頻,播放速度很不錯。雖說輕描淡寫但已經給出應用Asp.net開發視頻網站的思路。如果有興趣可以聯絡我。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.