C# ASP.NET Implementation

By grantph, 10 months ago.

To help the community along I've written a C# wrapper for OS FLV. All you need are the player.swf and rac.js file plus create a class from the following source:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YourNameSpace
{
	[DefaultProperty("FileName")]
	[ToolboxData("<{0}:FlashVideo runat=server></{0}:FlashVideo>")]
	public class FlashVideo : WebControl
	{
		private string fileName = string.Empty;
		public string FileName
		{
			get { return this.fileName; }
			set { this.fileName = value; }
		}

		private string playerPath = "/Flash/";
		public string PlayerPath
		{
			get { return this.playerPath; }
			set { this.playerPath = value; }
		}

		private int volume = 70;
		public int Volume
		{
			get { return this.volume; }
			set { this.volume = value; }
		}

		private bool autoLoad = false;
		public bool AutoLoad
		{
			get { return this.autoLoad; }
			set { this.autoLoad = value; }
		}

		protected override void OnLoad(EventArgs e)
		{
			// Register Javascript File
			if (this.Page.ClientScript.IsClientScriptBlockRegistered("FlashVideo") == false)
			{
				this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "FlashVideo", string.Format("<script charset='ISO-8859-1' language='javascript' src='{0}rac.js' type='text/javascript'></script>", this.PlayerPath));
			}

			base.OnLoad(e);
		}

		protected override void RenderContents(HtmlTextWriter Writer)
		{
			string html = string.Format(@"
<div>
<script language='javascript'>
var src = '{3}player';
if(!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) src = 'player8';
AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', 'width', {1}, 'height', {2}, 'src', src, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer',	'id', 'flvPlayer', 'allowFullScreen', 'true', 'movie', src, 'FlashVars','movie={0}&fgcolor=0x0b7ba4&bgcolor=0x333333&autoload={5}&autorewind=on&volume={4}');
</script>

<noscript>
<object id='flvPlayer' height='{2}' width='{1}'>
<param name='allowFullScreen' value='true'>
<param name='movie' value='{3}player.swf?movie={0}&fgcolor=0x0b7ba4&bgcolor=0x333333&autoload={5}&autorewind=on&volume={4}'>
<embed allowfullscreen='true' height='{2}' src='{3}player.swf?movie={0}&fgcolor=0x0b7ba4&bgcolor=0x333333&autoload={5}&autorewind=on&volume={4}'
type='application/x-shockwave-flash' width='{1}'></embed>
</object>
</noscript>
</div>
", HttpUtility.UrlEncode(this.FileName), this.Width.Value, this.Height.Value+40, this.PlayerPath, this.Volume, (this.AutoLoad ? "on" : "off"));
			// Height+40 is to compensate for Controls which are 40 pixels high.

			Writer.Write(html);
		}
	}
}

I've hardcoded the Flash directory as /Flash/ (relative to root) but you can modify it. Simply ensure that the player.swf and rac.js files are in that directory!

Regards,

Grant P Henderson

Thanks, Grant. This is great.

Posted 10 months ago #


RSS feed for this topic

New Topic

You must log in to post.

Copyright Jambo Media, LLC 2009

Powered by WordPress - Created by Tommaso Baldovino