65.9K
CodeProject is changing. Read more.
Home

Reader of SWF Header File in Pure C#

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.75/5 (10 votes)

Aug 10, 2007

CPOL
viewsIcon

119736

downloadIcon

2544

Reader of SWF header file in pure C# with a single class

Screenshot - SwfHeaderReader.jpg

Introduction

It's my first article on The Code Project. Please excuse my English.

This article describes how to read the header of the flash file. (This file has the extension .swf )

The Format Header SWF is described in this link.

You can also read a good article on SWF which describes the library SwfDotNet.

I wrote this article for myself and for people who want small source code.
To read this header, I translate PHP code to C#. The original source code in PHP is at this address.

This is the code of a class which can provide information of the Swf Flash:

  • FrameRate
  • FrameCount
  • Width
  • Height
  • Version

Warning, this class doesn't work with the compressed Flash File.

Using the Code

The name of the class is FlashHeaderReader and takes for the constructor a parameter, the filename of the flash file.

It calls these methods:

  • ReadSignature();
  • mVersion=GetNextByte();
  • ReadFileLength();
  • ReadFrameSize();
  • ReadFrameRate();
  • ReadFrameCount();

Later, you can access the properties of the swf file :

FlashHeaderReader swfreader = new FlashHeaderReader(openFileDialog1.FileName);

listBox1.Items.Clear();
listBox1.Items.Add("Frames : " + swfreader.FrameCount);
listBox1.Items.Add("Width : " + swfreader.Width );
listBox1.Items.Add("Height : " + swfreader.Height);

Points of Interest

The method ReadFrameSize is complex because the swf format also compresses the header and information has a different size.

History

  • 10th August, 2007: Initial post