This blog is subject the DISCLAIMER below.

Saturday, June 30, 2007

How to Play Flash (SWF) inside C#

Playing Flash (*.SWF) inside C# program with the ability to play ,pause and forward the movie :

All what you should to do in the first is to import the this two reference in the project as in this figure .
In the InitializeComponent function from Form.Designer.cs define your flash object as this :

this.AxShockwaveFlash1 = new AxShockwaveFlashObjects.AxShockwaveFlash();
then
//
// AxShockwaveFlash1
//
this.AxShockwaveFlash1.Enabled = true;
this.AxShockwaveFlash1.Location = new System.Drawing.Point(12, 12);
this.AxShockwaveFlash1.Name = "AxShockwaveFlash1";
this.AxShockwaveFlash1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("AxShockwaveFlash1.OcxState")));
this.AxShockwaveFlash1.Size = new System.Drawing.Size(525, 266);

To fill your Flash Object by SWF file:
AxShockwaveFlash1.Movie = “c:\ahmed.swf”;

To forward or pause the flash object :
AxShockwaveFlash1.Forward();

To Play the flash object :
AxShockwaveFlash1.Play();

21 comments:

Ramy Mahrous said...

Nice post, Essawy
You may got this error
Cannot initilize the component...

So Start->Run->

regsvr32 C:\Windows\system32\Macromed\Flash\flash7.ocx
OR
regsvr32 C:\Windows\system32\Macromed\Flash\flash8.ocx
OR
regsvr32 C:\Windows\system32\Macromed\Flash\flash9c.ocx

Just see your OCX version.

Anonymous said...

The download link is broken.
I also found this link useful http://blogs.vbcity.com/drydo/archive/2005/12/07/5731.aspx

ahmedNZ said...

Hello, where do you get those two dlls from. Thank You.

ahmedNZ said...
This comment has been removed by the author.
Ahmed Essawy said...

here are the links to the DLLs :

Interop.ShockwaveFlashObjects.dll :

http://ahmedessawy.googlepages.com/Interop.ShockwaveFlashObjects.dll


AxInterop.ShockwaveFlashObjects.dll :

http://ahmedessawy.googlepages.com/AxInterop.ShockwaveFlashObjects.dll

Anonymous said...

what is this resource??
resources.GetObject....
it gives me error

Unknown said...

Hi

This code is really good,but i am getting error at resource.getobject()... what is this resources. Please give reply

Bye

Ahmed Essawy said...

Dear Hossam and lavanya :

1- here is the resource file
http://ahmedessawy.googlepages.com/Form1.resx

2-I lost my project but here a VB.net code use the same dlls
http://ahmedessawy.googlepages.com/Flash_player.rar

ManojSharma said...

alternative solution is:
first add the flash object in tool box by right click -> com object-> flash object
then try this
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "swf File|*.swf";
openFileDialog1.FilterIndex = 2;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
axShockwaveFlash1.Stop();
axShockwaveFlash1.Movie = openFileDialog1.FileName;
axShockwaveFlash1.Play();
}
}

myncs said...

Hi, can you please tell me if it is possible to display a transparent swf in flash player in a WPF application. Any feedback would be greatly appreciated.

Ahmed Essawy said...

@myncs
yes, it is possible to open SWF Flash in your WPF application but keep in mind that
#Adobe does not officially support embedding the Macromedia Flash Player ActiveX control within a Windows application. This means that future versions of the player may not work with your application.

#It requires users to install the Adobe Flash Player ActiveX control on their computers. This can be done by installing the player within Microsoft Internet Explorer. Although it is technically possible to distribute the player, that is restricted by the player's end-user license agreement. If you need to distribute the Adobe Flash Player ActiveX control, contact Adobe for permission.

here is a great post by Janiv Ratso
to do that step by step and source code is also available :)

http://blogs.microsoft.co.il/blogs/janiv/archive/2009/09/20/embedding-and-communicating-with-the-macromedia-flash-player-in-wpf.aspx

Muthu said...

I have embedded flash control to my C# app and am able to load swf files dynamically. I would like to send information to the swf (for example, my swf file picks data from an external text file) i want to be able to give the name of the text file to the swf file. how can i do this?

Ahmed Essawy said...

@Muthu I didn't try that before but it is applicable and can be done very easy.
you can google for that use key words like
"how to pass parameter from C# to flash swf".

and here two result that I think may help you :)

http://www.shinedraw.com/browser-integration/silverlight-vs-flash-passing-query-string-parameters/

http://www.friendsofed.com/samples/1590595173.pdf

Anonymous said...

I try to add flash object in vs2008
it gives a exception
in designer.cs


Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

if anyone know a solution Please reply

Anonymous said...

Re: Class not registered (Exception from HRESULT:

you must change project property - bulid - platworm x86 in other words ocx won't work when x64 or any cpu is selected

Anonymous said...

is this possible in c# 2005 ?

Ahmed Essawy said...

yes just write the same code in VS 2005. :)

pconnoll said...

Essawy, The DLL download link is broken. Will you provide another link or explain further in how I may be able to obtain the Interop.ShockwaveFlashObjects.dll and AxInterop.ShockwaveFlashObjects.dll.

Thanks...

Ahmed Essawy said...

Dear pconnoll,
try this link :)
http://ahmedessawy.googlepages.com/Flash_player.rar

pconnoll said...

Essawy,

Thank you for the updated link.

-Paul

Anonymous said...

How to play exe flash files ?