473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How To Play Flash Video Files In ASP.NET using C#.net or VB.net

85 New Member
There is a few different ways to show video on web page. Most popular are Windows Media Player, Quick Time, Adobe Flash or Silverlight. If you want to find out how to show video with Windows Media Player you can read How to build ASP.NET Media Player Control tutorial.

This tutorial will focus on using of Flash to show flash video files on ASP.NET web site.

Flash becomes widely used and today it is most used technology for showing movies on Internet. Flash is used by most popular video sharing web sites like YouTube or Google Video. It is compatible with almost every operating system and web browser and very prevalent on Internet users computers. To see Flash movies, users need to have Flash player installed. On my experiences, at least 95% visitors have Flash player installed which is more than other available technologies. Flash is client side technology, although it can be used with static HTML page, but it is usually manipulated by server side web application.
You can’t show flash video files directly. Flash is just a programming framework, which uses Action Script programming language. You need a program made in Flash (video player) to show .flv video on page. You can of course learn Action Script and develop your own player, but that is out of scope of this tutorial. I will leave that task to Flash developers. Fortunately, there are already some free and very good Flash video players available. Using of them will short your development cycle and provide you a quality solution. I selected JW FLV Player as the best solution.

Using of JW FLV Player on web page

There are a two basic steps when placing Flash application to web page:
  • First, declare and initiate a Flash object
  • Second, set properties of object according to your needs.
You can do this on two different ways, with static HTML tags <OBJECT > and , or by using a JavaScript.

With static HTML your code could look something like this:
Expand|Select|Wrap|Line Numbers
  1. <object width=”640″ height=”480″>
  2. <param name=”movie” value=”player.swf” />
  3. </object>
We need both <object > and tags to get browser compatibility. Internet Explorer uses <object> tag, but Firefox and Netscape can’t see it and recognize just . We set parameters by using <param > tags, and inside tag.

Code example above have added parameter name “movie” and value “player.swf”. You can add any other parameter on the same way.

Complete list of supported parameters for JW FLV Player you can see at their Flash vars page.
http://cdn5.tribalfusion.com/media/2...300x250_v8.swf

There is a problem with static HTML if visitors access with Internet Explorer. Flash application would not start until visitor clicks on it. If you just place a cursor over a movie you’ll see an ugly border. Common way to avoid need to click every time when page load is to initiate Flash player with JavaScript. JavaScript code for starting Flash movie could look like this:
Expand|Select|Wrap|Line Numbers
  1. <p id=’preview’>The player will show in this paragraph</p>
  2. <script type=’text/javascript’ src=’swfobject.js’></script>
  3. <script type=’text/javascript’>
  4. var s1 = new SWFObject(‘player.swf’,'player’,’400′,’300′,’9′);
  5. s1.addParam(‘allowfullscreen’,'true’);
  6. s1.addParam(‘allowscriptaccess’,'always’);
  7. s1.addParam(‘flashvars’,'file=video.flv’);
  8. s1.write(‘preview’);
  9. </script>
As you can see, nothing complicated here. Code creates SWFObject dynamically and then set its parameters. In this case visitor is not required to click to start a movie. Of course, JavaScript must be enabled in visitor’s web browser.

Manipulating Flash Player with ASP.NET

Basically, playing video files with JW FLV Player is simple, you just create an object and set needed parameters as in two code examples above. But, if you work with large number of video files or you need to enable to your users to add their movies you need to automate things. Writing static HTML code for every video certainly not sounds professional. Fortunately, with a little ASP.NET code we can make this task much easier .

Creating a custom ASP.NET Flash Player Control
Basic idea is this: Custom ASP.NET control will have properties related to JW FLV Player parameters. In run time, control will render appropriate content on client side so JW FLV player will show video correctly, and you can manipulate flash videos with ASP.NET web application. Now, we can create admin ASP.NET pages, load videos from database, enable database search etc., without hard coding.

I created ASP.NET JW FLV Flash Video Player Control that do this task. Control is free and you can use it to show Flash video files on your web site. Source code of control is also available in C# andVB.NET. Example web project is included in download to see how it works.
Flash Player Control Code Analysis
As you can see from C# and VB.NET code listings, control code consists from three parts:
1. Declaring of properties default values on the beginning. For server control, I used same default values like JW FLV Flash player already uses. I added two additional properties to describe location of JW FLV .swf and .js file, like in code bellow.
[ C# ]
Expand|Select|Wrap|Line Numbers
  1. #region Properties defaults
  2. const string DefaultSwfobject_jsLocation = “”; // in the same directory
  3. const string DefaultFlashPlayerLocation = “”; // in the same directory
  4. const bool DefaultAllowFullScreen = true;
  5. const string DefaultFile = “”;
  6. const bool DefaultAutoStart = false;
  7. const int DefaultBufferLength = 1;
  8. #endregion
[ VB.NET ]
Expand|Select|Wrap|Line Numbers
  1. #Region ”Properties defaults”
  2. Const DefaultSwfobject_jsLocation As String = “” ’ in the same directory
  3. Const DefaultFlashPlayerLocation As String = “” ’ in the same directory
  4. Const DefaultAllowFullScreen As Boolean = True
  5. Const DefaultFile As String = “”
  6. Const DefaultAutoStart As Boolean = False
  7. Const DefaultBufferLength As Integer = 1
  8. #End Region
2. Value of every property is saved to ViewState if value is different from default value. For example, code for AllowFullScreen property looks like this:
[ C# ]
Expand|Select|Wrap|Line Numbers
  1. [Bindable(true), Category("Settings")]
  2. bool AllowFullScreen
  3. {
  4.   get
  5.   {
  6.     if(ViewState["AllowFullScreen"] == null)
  7.       return DefaultAllowFullScreen;
  8.     else
  9.       return (bool)ViewState["AllowFullScreen"];
  10.   }
  11.   set
  12.   {
  13.      if(value != DefaultAllowFullScreen)
  14.         ViewState["AllowFullScreen"] = value;
  15.       else
  16.         ViewState["AllowFullScreen"] = null;
  17.   }
  18. }
[ VB.NET ]
Expand|Select|Wrap|Line Numbers
  1. <Bindable(True), Category(“Settings”)> _
  2. Property AllowFullScreen() As Boolean
  3.   Get
  4.     If ViewState(“AllowFullScreen”) Is Nothing Then
  5.       Return DefaultAllowFullScreen
  6.     Else
  7.       Return ViewState(“AllowFullScreen”)
  8.     End If
  9.   End Get
  10.   Set(ByVal value As Boolean)
  11.     If value <> DefaultAllowFullScreen Then
  12.       ViewState(“AllowFullScreen”) = value
  13.     Else
  14.         ViewState(“AllowFullScreen”) = Nothing
  15.     End If
  16.   End Set
  17. End Property
3. RenderContents function produces output to, depended of values of every property, correctly initialize Flash player on client side by using a JavaScript, like mentioned before.

Conclusion

With custom ASP.NET Flash Player control that manipulate client side flash player you can save a lot of time. I tested control in Firefox and Internet Explorer and worked fine. Please let me know if you find some bug or you have a suggestion for improvement.
Going professional with ASPNetFlashVideo
Control introduced in this tutorial is useful in some simpler scenarios, but keep in mind that JW FLV Player is free only for noncommercial projects. Fortunately, there is pure ASP.NET control namedASPNetFlashVideo that allows you to effortlessly incorporate beautiful Adobe Flash Video (FLV) media into ASP.NET website. For $49 you can use it on single site or just $99 for use on unlimited number of web sites. Except common interface commands for playing flash video files, ASPNetFlashVideosupports skins, custom user interface, play lists, integration with Visual Studio, search engine optimization and more. Things like no ongoing subscription costs, free future updates or 30 days money back guarantee justify decision to give it a try.
Aug 1 '12 #1
0 20122

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: jaffar | last post by:
hi, i am developing a windows application, in my application i have to stor video files into database and play those video files from database , how to da this application, send me replay as...
13
by: anil.rita | last post by:
When the user chooses an AV file to play, based upon the type of file, I want to use the default installed media player to play it. I am wondering if this is a good way - any alternatives,...
0
by: leoiser | last post by:
hi all, I want to play 8 video files in a form.Little explanation abt my task.I am generating contols at runtime(getting data from webservice).so my form will have maximum 8 video controls at a...
12
by: smarsh | last post by:
Hi, I don't know PHP but it seems like the way to do this: I need a home page that loads a flash video into the HTML page and auto-plays for 1st time visitors. Repeat visitors (within 15 days)...
3
by: santel | last post by:
Hi, I tried to display the video files in C# forms using vlc. By refering this link http://www.codeproject.com/useritems/LiquidVideo.asp, I displayed the video files. But it accepts only .mpg...
5
by: mratanudey83 | last post by:
With the help of this forum members and google search i've done the following part Imports AxShockwaveFlashObjects Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object,...
0
by: starringstars | last post by:
Hi, Please help ? Is there a way to control a flashmovie from my webserver so that it will send a pauzevideo command to my flashvideo. I mean like you will see the video and it will automatically...
0
by: venkatu2005 | last post by:
Hii I am worked with CSharp - Windows Application... I want to play a video files , can any one post the code ..?? how shall i place the player control to my form........?
0
by: keith2045 | last post by:
I'm trying to create a plugin that will play flash videos (via a http network stream). I found some code that will play swf files (not sure about network swf files, cant get it working to test it....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.