none
Flash in WPF?

    Question

  • I would like to know if there are any method to host flash files directly in a WPF client-based browser application?
    Thursday, July 12, 2007 9:26 AM

Answers

  • You'd need to check the licensing for the control -- but there is an ActiveX control for Flash that is used within IE for showing Flash content. You could use VS to create a WinForm wrapper, then use the WindowsFormHost WPF element to show that control.

    Or you could host the WebBrowser and use a web page that shows the Flash control.

    Again, the license for Flash may not permit these uses.
    Thursday, July 12, 2007 5:27 PM
  • I have a WPF application that plays Flash - but using a windows form to do it. This is done using the activeX control from Shockwave. This was done by choosing "Add Reference" ; choose "COM" page and navigate down the list to the Shockwave Flash control and selecting the Shockwave Flash player object. Be careful; there seem to be two versions floating around. You want the "ShockwaveFlashClass" one.

     

    The way to identify the right one is that it has the key method:

          LoadMovie(int, string);

     

    This method can be seen through the object browser (View-ObjectBrowser) If you do not see that method - you have the wrong guy. Once the right one is loaded, there will be a Shockwave ActiveX control in your Toolbox (View->Toolbox). That can be dragged to a Windows Form (WPF) and will result in the following being added to the Form1.Designer.cs:

     

    private AxShockwaveFlashObjects.AxShockwaveFlash axShockwaveFlash1;

     

    Now the flash can be played by adding a public method to the form code-behind:

     

    public void PlayFlash(string path)

    {

           if (File.Exists(path))

            {

                 // Play the file

                axShockwaveFlash1.LoadMovie(0, path);

              axShockwaveFlash1.Play();

           }

    }

     

    I hope that helps.

     

    I tried, but could never get it to work with a <Window> or any other WPF container. It seems that only a WinForm pumps the right ActiveX messages to the control to make it work.  If you can mak it work in something other than a WinForm, please enlighten me!

     

    -Matt

    Thursday, July 12, 2007 11:36 PM
  • I haven't tried this yet, but will be doing so in the very near future.

    I would try putting it into a user control. Here is an example of how to do this with the pdf control and should be easy to translate to any activex control.

    http://blogs.msdn.com/mhendersblog/archive/2005/09/23/473065.aspx

    The example code is from earlier releases and will not compile, so change the line
                 host.children.Add(mycontrol)
    to:
                 host.Child = mycontrol;

    You have to write your own "wrapper" methods in your user control.
               
     Let us know how it works out!
    Friday, July 13, 2007 2:04 PM

All replies

  • You'd need to check the licensing for the control -- but there is an ActiveX control for Flash that is used within IE for showing Flash content. You could use VS to create a WinForm wrapper, then use the WindowsFormHost WPF element to show that control.

    Or you could host the WebBrowser and use a web page that shows the Flash control.

    Again, the license for Flash may not permit these uses.
    Thursday, July 12, 2007 5:27 PM
  • I have a WPF application that plays Flash - but using a windows form to do it. This is done using the activeX control from Shockwave. This was done by choosing "Add Reference" ; choose "COM" page and navigate down the list to the Shockwave Flash control and selecting the Shockwave Flash player object. Be careful; there seem to be two versions floating around. You want the "ShockwaveFlashClass" one.

     

    The way to identify the right one is that it has the key method:

          LoadMovie(int, string);

     

    This method can be seen through the object browser (View-ObjectBrowser) If you do not see that method - you have the wrong guy. Once the right one is loaded, there will be a Shockwave ActiveX control in your Toolbox (View->Toolbox). That can be dragged to a Windows Form (WPF) and will result in the following being added to the Form1.Designer.cs:

     

    private AxShockwaveFlashObjects.AxShockwaveFlash axShockwaveFlash1;

     

    Now the flash can be played by adding a public method to the form code-behind:

     

    public void PlayFlash(string path)

    {

           if (File.Exists(path))

            {

                 // Play the file

                axShockwaveFlash1.LoadMovie(0, path);

              axShockwaveFlash1.Play();

           }

    }

     

    I hope that helps.

     

    I tried, but could never get it to work with a <Window> or any other WPF container. It seems that only a WinForm pumps the right ActiveX messages to the control to make it work.  If you can mak it work in something other than a WinForm, please enlighten me!

     

    -Matt

    Thursday, July 12, 2007 11:36 PM
  • I haven't tried this yet, but will be doing so in the very near future.

    I would try putting it into a user control. Here is an example of how to do this with the pdf control and should be easy to translate to any activex control.

    http://blogs.msdn.com/mhendersblog/archive/2005/09/23/473065.aspx

    The example code is from earlier releases and will not compile, so change the line
                 host.children.Add(mycontrol)
    to:
                 host.Child = mycontrol;

    You have to write your own "wrapper" methods in your user control.
               
     Let us know how it works out!
    Friday, July 13, 2007 2:04 PM
  • Hello Matt

     

    I have done exactly as you suggested, but there was no Shockwave ActiveX control added to my toolbox.

    Maybe I have the wrong "ShockwaveFlashClass", I am using "Flash9d.ocx", how can I get your version?

     

     

    Many Thanks!!!

    Sunday, July 22, 2007 11:19 AM
  • I have re-edited this with more precise information.

     

    The control was added through add reference -> COM -> Shockwave Flash.

     

    There was also an "Shockwave ActiveX Control" listed - but that is NOT the right one.

     

    The correct control file was:

     

    C:\Windows\System32\Macromed\Flash\Flash9d.ocx

     

    I hope this was helpful,

     

     

    Friday, August 24, 2007 5:55 PM