惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

博客园 - peak

windows 服务器时间同步失败处理方法 利用批处理自动创建schtasks系统任务 抓取网站编码信息及内容 在线调试利器Fiddler AutoResponse jquery跨域调用WCF Base-64 字符串中的无效字符 Ie7下鼠标滚轮失效 Android 笔记二(取得根目录权限) Android 笔记一 捕获asp.net ValidationSummary 控件消息。 - peak Sql Split 函数 Rss的浏览器之痛 兼容IE,Firefox 图片即时显示 迷茫 windows service 之访问权限 windows Service 之调试过程 比尔盖兹在某个大学毕业典礼上的演讲中,对毕业生提出十一项极为睿智的人生建议 MSDN上关于泛型的例子 泛型
asp.net 中插入flash - peak - 博客园
peak · 2008-09-04 · via 博客园 - peak

最近写了一个关于在asp.net 下,播放flash 的东西。其实,这东西大家都很熟悉,网上关于此类的代码也很多,但是请注意下边代码的红色注释,flash文件为本工程下的目录。
如:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
                        width
="575" height="375" align="middle">
                        
<param name="movie" value='/flashs/flash.swf''注意:此处为该工程下的相对目录
                        <param name="quality" value="high">
                        
<param name="wmode" value="Transparent" />
                        
<param name="menu" value="false" />
                        
<param name="FlashVars" value="init=yes&check=true" />
                        
<embed src='/flashs/flash.swf'''  ——注意:此处为该工程下的相对目录
                        quality
="high" wmode="transparent" width="575" height="375"
                            name
="fileUpload" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash"
                            pluginspage
="http://www.macromedia.com/go/getflashplayer" /></object>

可是如果要是工程外部的目录或者是其他的磁盘映射,这么是无法工作的。那怎么办呢!功夫不负我这样的有心人,终于在网上找到一关于把flash 转换成stream 的一个方法,经过一点小的改动完成。
如下:
FLVStreamHandler 代码

<%@ WebHandler Language="C#" Class="FLVStreamHandler" %>using System;
using System.Web;
using System.IO;
using Tribal.Tsite.API;
using Tribal.Tsite.Implementation;public class FLVStreamHandler : IHttpHandler {private static readonly byte[] _flvheader = HexToByte("464C5601010000000900000009"); //"FLV\x1\x1\0\0\0\x9\0\0\0\x9"
    
    
public void ProcessRequest (HttpContext context) 
    {
        
       
        
        
try
        {
            
int pos;
            
int length;// Check start parameter if present
            
//string filename = Path.GetFileName(context.Request.FilePath);
            int flashId = int.Parse(context.Request.QueryString["Id"]);
            MainController mainController 
= MainController.GetInstance();
            IFlashFile flashFile 
= mainController.FlashFileController.GetFlashFileById(flashId);string flashPath = "";
            
if (File.Exists(flashFile.FilePath + flashFile.FileName))
                flashPath
=flashFile.FilePath + flashFile.FileName;
            
else
                flashPath 
= context.Server.MapPath("~/App_Themes/Normal/Images/default.swf");
                
            
using (FileStream fs = new FileStream(flashPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                
string qs = context.Request.Params["start"];if (string.IsNullOrEmpty(qs))
                {
                    pos 
= 0;
                    length 
= Convert.ToInt32(fs.Length);
                }
                
else
                {
                    pos 
= Convert.ToInt32(qs);
                    length 
= Convert.ToInt32(fs.Length - pos) + _flvheader.Length;
                }
// Add HTTP header stuff:clear cache, content type and length        
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//注意:如果每次打开都不变换flash文件,请使用缓存
              //context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Cache.SetExpires(DateTime.Now.AddDays(
-1));
                context.Response.Cache.SetLastModified(DateTime.Now);

                context.Response.AppendHeader(

"Content-Type""video/x-flv");
                context.Response.AppendHeader(
"Content-Length", length.ToString());
                
                
// Append FLV header when sending partial file
                if (pos > 0)
                {
                    context.Response.OutputStream.Write(_flvheader, 
0, _flvheader.Length);
                    fs.Position 
= pos;
                }
// Read buffer and write stream to the response stream
                const int buffersize = 16384;
                
byte[] buffer = new byte[buffersize];int count = fs.Read(buffer, 0, buffersize);
                
while (count > 0)
                {
                    
if (context.Response.IsClientConnected)
                    {
                        context.Response.OutputStream.Write(buffer, 
0, count);
                        count 
= fs.Read(buffer, 0, buffersize);
                    }
                    
else
                    {
                        count 
= -1;
                    }
                }
            }
        }
        
catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
    }
 
    
public bool IsReusable 
    {
        
get 
        {
            
return false;
        } 
    }
private static byte[] HexToByte(string hexString)
    {
        
byte[] returnBytes = new byte[hexString.Length / 2];
        
for (int i = 0; i < returnBytes.Length; i++)
            returnBytes[i] 
= Convert.ToByte(hexString.Substring(i * 22), 16);
        
return returnBytes;
    }

}

前台代码:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
                        width
="575" height="375" align="middle">
                        
<param name="movie" value='http://www.cnblogs.com/Handler/FLVStreamHandler.ashx?Id=<%=FlashFileId %>'>注意:通过FLVStreamHandler.ashx把fllash流化
                        <param name="quality" value="high">
                        
<param name="wmode" value="Transparent" />
                        
<param name="menu" value="false" />
                        
<param name="FlashVars" value="init=yes&check=true" />
                        
<embed src='http://www.cnblogs.com/Handler/FLVStreamHandler.ashx?Id=<%=FlashFileId %>' quality="high" wmode="transparent" width="575" height="375"
                            name
="fileUpload" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash"
                            pluginspage
="http://www.macromedia.com/go/getflashplayer" /></object>

以上是我在开发时,解决asp.net 中插入flash的一种方法。