Create a preview player for Flash (SWF) files

Adobe Flash movies are a popular file format. The ADAM engine has no issues in storing those file formats, but there is no out-of-the-box preview player. However, creating such a preview player is pretty straight forward.

The basics

To create a custom preview player, you should subclass the abstract class FileVersionView..This class is the base class for all preview players in ADAM.

To create the HTML that provides a preview of the Flash file, you can add HtmlGenericControl controls as a child controls and set the necessary properties to it in order to output standard HTML for embedding a Flash file:

To determine the URL of the Flash file, you need access to the FileVersion being previewed. This object is available in the DataItem property of the FileVersionView control. The FileVersion object has a property Path which contains the local (or network) path of the actual file. To convert this path into an URL, you can use a ServerFileUri object to create a secure URL from it.

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
protected override void CreateChildControls()
{
  FileVersion version = this.DataItem as FileVersion;
  if(version != null && string.IsNullOrEmpty(version.Path) == false)
  {
    string path = version.Path;
    
    ServerFileUri uri = new ServerFileUri(path, "application/x-shockwave-flash");
    string url = uri.ToString();
  
    HtmlGenericControl control = new HtmlGenericControl("object");
  
    HtmlGenericControl param = new HtmlGenericControl("param");
    param.Attributes.Add("name", "movie");
    param.Attributes.Add("value", url);
    control.Controls.Add(param);
  
    HtmlGenericControl embed = new HtmlGenericControl("embed");
    embed.Attributes.Add("src", url);
    embed.Attributes.Add("type", "application/x-shockwave-flash");
    control.Controls.Add(embed);
  
    this.Controls.Add(control);
  }
  else
  {
    this.Controls.Add(new LiteralControl("No FileVersion available or the file could not be found."));
  }
}

Note: the code above is a stripped down version and only contains the minimal required HTML properties to embeds a Flash file into an HTML page. When using the code in a production environment, you should complete the code to provide all properties. To get more information about which properties are available, there are dozens of articles on the web. We suggest following articles:

Macromedia Flash OBJECT and EMBED tag syntax
Flash OBJECT and EMBED tag attributes.

Using the preview player in ADAM

A preview player is a provider. Therefore, once the code of the preview player is completed, you must register the containing assembly in ADAM and add the preview player in the 'Preview Render Web Control Providers' setting. More information on registering and configuring a provider in ADAM can be found in the topic 'Creating a custom provider' of the ADAM development guide,

Once this is done, open up the Config Studio, go to 'File Type Management', search for the SWF file type and add the Flash preview player to the list of preview players.

Configuring the preview player

The abstract class FileVersionView has an additional virtual method: ApplyProviderSettings. This method has one parameter (settings) which contains the additional XML attributes set on the <add /> tag of the corresponding preview player configured in theĀ  'Preview Render Web Control Providers' setting. You can use this method to configure your preview player.

By example, you could add configuration options to the preview player to control its width and height. To achieve this, add these properties in the setting. E.g.:

XML
1
<add name="FlashPreviewPlayer" type="Sample.FlashPreviewPlayer, Sample" width="600px" height="400px" />

You can now read these options in the ApplyProviderSettings method:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
private Unit _width = Unit.Empty;
private Unit _height = Unit.Empty;

public override void ApplyProviderSettings(IDictionary<string, string> settings)
{
  if (settings != null)
  {
    if (settings.ContainsKey("width") == true)
    {
      string width = settings["width"];
      if (string.IsNullOrEmpty(width) == false)
      {
        try
        {
          _width = Unit.Parse(width);
        }
        catch
        {
          _width = Unit.Empty;
        }
      }
    }

    if (settings.ContainsKey("height") == true)
    {
      string height = settings["height"];
      if (string.IsNullOrEmpty(height) == false)
      {
        try
        {
          _height = Unit.Parse(height);
        }
        catch
        {
          _height = Unit.Empty;
        }
      }
    }
  }
  base.ApplyProviderSettings(settings);
}

Downloads

You must be logged in to download the files.
Sign in now

Comments

Monday, 04 January 2010Hans De Potter says
@Luc: A new article has been posted about playing FLV files in ADAM.

@Serge: As you mentioned, you can convert FLV files so they can be viewed with the out-of-the-box solution of ADAM. The new article describes how you can play FLV files directly by implementing a custom preview player for FLV files.
Sunday, 22 November 2009Serge Bonehill says
@Luc Naets: FLV is supported by the media engine Microsoft Expression Encoder and will play out of the box using that engine.
Tuesday, 17 November 2009Luc Naets says
Is it also possible to show how to play flv files?
Leave a comment
You must be logged in to post comments.
Sign in now
 
 
CATEGORIES
AnnouncementsDocMaker StudioEngineSharePoint ConnectorWeb DevelopmentWebinarsWorkflow Studio
rss feed