Click here to Skip to main content
15,885,757 members
Articles / Programming Languages / C#

Reader of SWF Header File in Pure C#

Rate me:
Please Sign up or sign in to vote.
3.75/5 (10 votes)
10 Aug 2007CPOL 118.1K   2.5K   30   23
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 :

C#
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) http://www.cmb-soft.com/
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow does it handle garbage collection i cant dispose reader object Pin
SeekKnowledge9-Dec-12 19:12
SeekKnowledge9-Dec-12 19:12 
AnswerRe: How does it handle garbage collection i cant dispose reader object Pin
zebulon750187-May-13 9:09
zebulon750187-May-13 9:09 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 21:12
professionalManoj Kumar Choubey26-Feb-12 21:12 
NewsCode Snipped to implement Duration Pin
Horst Klein24-Nov-11 0:59
Horst Klein24-Nov-11 0:59 
Questioninfo shown are totally off Pin
Member 842930423-Nov-11 22:53
Member 842930423-Nov-11 22:53 
GeneralMy Vote of 5 Pin
Alan Burkhart11-Jun-11 6:12
Alan Burkhart11-Jun-11 6:12 
GeneralRe: My Vote of 5 Pin
zebulon750187-May-13 9:07
zebulon750187-May-13 9:07 
GeneralMy vote of 1 Pin
gunjan9um13-Jul-09 1:36
gunjan9um13-Jul-09 1:36 
GeneralMy vote of 1 Pin
crayzeecoder25-Jun-09 21:45
crayzeecoder25-Jun-09 21:45 
GeneralRead FLV and Real Media file meta data Pin
Vishal Dedaniya22-Dec-08 10:42
Vishal Dedaniya22-Dec-08 10:42 
GeneralRe: Read FLV and Real Media file meta data Pin
Member 438714318-Feb-09 3:16
Member 438714318-Feb-09 3:16 
QuestionCan we read Compressed SWF files Pin
Shikhardadhich17-Sep-08 20:31
Shikhardadhich17-Sep-08 20:31 
AnswerRe: Can we read Compressed SWF files Pin
zebulon750181-Dec-08 9:09
zebulon750181-Dec-08 9:09 
GeneralImproving read efficiency Pin
dssdss11-Oct-07 18:18
dssdss11-Oct-07 18:18 
GeneralRe: Improving read efficiency Pin
zebulon7501812-Oct-07 2:34
zebulon7501812-Oct-07 2:34 
QuestionVector info? Pin
Vuvirt10-Oct-07 9:34
Vuvirt10-Oct-07 9:34 
AnswerRe: Vector info? Pin
zebulon7501812-Oct-07 2:39
zebulon7501812-Oct-07 2:39 
GeneralRe: Vector info? Pin
Vuvirt14-Oct-07 22:49
Vuvirt14-Oct-07 22:49 
QuestionDoes this work with FLV files?? Pin
dclark12-Aug-07 13:01
dclark12-Aug-07 13:01 
AnswerRe: Does this work with FLV files?? Pin
SteveSM214-Aug-07 22:55
professionalSteveSM214-Aug-07 22:55 
GeneralRe: Does this work with FLV files?? Pin
zebulon7501819-Aug-07 23:30
zebulon7501819-Aug-07 23:30 
AnswerRe: Does this work with FLV files?? I guess No :( Pin
zebulon7501819-Aug-07 23:27
zebulon7501819-Aug-07 23:27 
GeneralRe: Does this work with FLV files?? Pin
zebulon750186-Feb-08 3:35
zebulon750186-Feb-08 3:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.