For playing .flv file mediaplayer.swf is needed.

<asp:Literal ID=”litVideo” runat=”server”></asp:Literal>
C# code :
string filename = “Media/test.wmv”;
string code = string.Empty;
string browserType = Request.Browser.Type;
int height = 0;
int width = 0;
int marginUp = 0;
int marginRight = 0;
int marginDown = 0;
int marginLeft = 0;

if (filename.ToLower().EndsWith(“.wmv”))
{
int start = HttpContext.Current.Request.Url.AbsoluteUri.IndexOf(HttpContext.Current.Request.Url.AbsolutePath);
string hostName = HttpContext.Current.Request.Url.AbsoluteUri.Remove(start);

if (!hostName.EndsWith(“/”))
hostName += “/”;

string appPath = HttpContext.Current.Request.ApplicationPath;
if (appPath.StartsWith(“/”))
appPath = appPath.Remove(0, 1);

hostName += appPath;

if (!hostName.EndsWith(“/”))
hostName += “/”;

if (browserType.StartsWith(“IE”))
{
height = 307;
width = 545;
marginUp = 30;
marginRight = 0;
marginDown = 0;
marginLeft = 30;
}
else if (browserType.ToLower().StartsWith(“firefox”))
{
height = 420;
width = 610;
marginUp = 10;
marginRight = 3;
marginDown = 10;
marginLeft = 3;
}
else
{
height = 307;
width = 545;
marginUp = 65;
marginRight = 0;
marginDown = 0;
marginLeft = 38;
}

code = string.Format(@”<div style=””margin: {0}px {1}px {2}px {3}px; overflow:hidden””>http://”4”<div>”, marginUp, marginRight, marginDown, marginLeft, hostName + filename, width, height);
}

else if (filename.ToLower().EndsWith(“.mov”))
{
if (browserType.StartsWith(“IE”))
{
height = 407;
width = 602;
marginUp = 3;
marginRight = 3;
marginDown = 3;
marginLeft = 3;
}
else if (browserType.ToLower().StartsWith(“firefox”))
{
height = 420;
width = 610;
marginUp = 10;
marginRight = 3;
marginDown = 10;
marginLeft = 3;
}
else
{
height = 416;
width = 610;
marginUp = 10;
marginRight = 3;
marginDown = 10;
marginLeft = 3;
}

int start = HttpContext.Current.Request.Url.AbsoluteUri.IndexOf(HttpContext.Current.Request.Url.AbsolutePath);
string hostName = HttpContext.Current.Request.Url.AbsoluteUri.Remove(start);

if (!hostName.EndsWith(“/”))
hostName += “/”;

string appPath = HttpContext.Current.Request.ApplicationPath;
if (appPath.StartsWith(“/”))
appPath = appPath.Remove(0, 1);

hostName += appPath;

if (!hostName.EndsWith(“/”))
hostName += “/”;

code = string.Format(@”<object classid=””clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B”” codebase=””http://www.apple.com/qtactivex/qtplugin.cab”&#8221; height=””{5}”” width=””{4}””>
<param name=””src”” value=””{6}”” />
<param name=””autoplay”” value=””true”” />
<param name=””controller”” value=””true”” />
<PARAM NAME=””ShowStatusBar”” VALUE=””true”” />
http://”6”
</object>”, marginUp, marginRight, marginDown, marginLeft, width, height, hostName + filename);

}
else if (filename.ToLower().EndsWith(“.flv”))
{
if (browserType.StartsWith(“IE”))
{
height = 407;
width = 602;
marginUp = 3;
marginRight = 3;
marginDown = 3;
marginLeft = 3;
}
else if (browserType.ToLower().StartsWith(“firefox”))
{
height = 420;
width = 610;
marginUp = 10;
marginRight = 3;
marginDown = 10;
marginLeft = 3;
}
else
{
height = 416;
width = 610;
marginUp = 10;
marginRight = 3;
marginDown = 10;
marginLeft = 3;
}

code = string.Format(@”<div id=””container”” style=””margin: {0}px {1}px {2}px {3}px; overflow:hidden;””>
<a href=””http://www.macromedia.com/go/getflashplayer””>Get the Flash Player</a> to see this player.
</div>

<script type=””text/javascript””>
var s1 = new SWFObject(“”../mediaplayer.swf””, “”mediaplayer””, “”{4}””, “”{5}””, “”8″”);
s1.addParam(“”allowfullscreen””, “”true””);
s1.addParam(“”autostart””, “”true””);
s1.addVariable(“”width””, “”{4}””);
s1.addVariable(“”height””, “”{5}””);
s1.addVariable(“”file””, “”{6}””);
s1.write(“”container””);
</script>”, marginUp, marginRight, marginDown, marginLeft, width, height, filename);
}
else
{
code = “Video format is not supported!”;
}

litVideo.Text = code;

Advertisements