embedding a flash file in JSP page

Posted on 2005-04-19
Last Modified: 2010-04-01

I’m embedding a flash file in JSP page and the file is coming from database and every time this is a different file.
Some flash files are of different size. As flash file is not taking default dimension (like an image) in the Browser so I need to specify the dimension (width, height).

How can I fetch the Attributes (width, height) of a flash file so that I can put the dimension dynamically?
Question by:kamarrizwan
    LVL 35

    Expert Comment

    According to this:

    you should be able to read the first few bytes of the swf file, and find out the width and height:

    SWF File Header      
         Field                Type*      Comment    
         Signature        byte              Signature byte always ‘F’    
         Signature        byte              Signature byte always ‘W’    
         Signature        byte              Signature byte always ‘S’    
         Version           byte         Single byte file version (e.g. 0x04F for SWF 4)    
         FileLength       int            Length of entire file in bytes    
         FrameSize      RECT      Frame size in twips    

    where "RECT" is of the format:

         Field        Type                 Comment    
         Nbits       nBits = UB[5]     Bits used for each subsequent field    
         Xmin       SB[nBits]            X minimum position for rectangle in twips    
         Xmax      SB[nBits]            X maximum position for rectangle in twips    
         Ymin            SB[nBits]            Y minimum position for rectangle in twips    
         Ymax      SB[nBits]           Y maximum position for rectangle in twips  
    LVL 35

    Expert Comment

    Any use?


    LVL 1

    Author Comment

    Hi TimYates,
    thanks for workout.
    As i'm new to jsp, still trying to got the solution. can you please help me out to understand the code in better way.
    LVL 35

    Accepted Solution

    Basically, you'll need to open a DataInputStream that points to the file:

        DataInputStream dis = new DataInputStream( new FileInputStream( "flashfile.swf" ) ) ;

    then, skip the first 8 bytes (up to and including filesize according to the header)

        dis.skip( 8 ) ;

    then, read 5 bytes in.  These will represent the number of bits used for each of x, y, w, h

        byte[] nBits = new byte[ 5 ] ;
        dis.readFully( nBits, 0, 5 ) ;

    then, convert this to a long (THIS WILL DEPEND WHICH WAY ROUND THE NUMBERS ARE ENCODED IN THE FILE) :-(  Have a look with a hex editor...  I'm assuming they're little-endian

        long n = ( nBits[ 0 ] & 0xff ) |
                      ( ( nBits[ 1 ] & 0xFF ) << 8 ) |
                      ( ( nBits[ 2 ] & 0xFF ) << 16 ) |
                      ( ( nBits[ 3 ] & 0xFF ) << 24 ) |
                      ( ( nBits[ 4 ] & 0xFF ) << 32 ) |
        out.println( "Apparently, there are " + n + " bits per field" ) ;

    then, read the xmin, xmax, ymin, ymax values:

        byte[] xmin = new byte[ n ] ;
        byte[] xmax = new byte[ n ] ;
        byte[] ymin = new byte[ n ] ;
        byte[] ymax = new byte[ n ] ;
        dis.readFully( xmin, 0, n ) ;
        dis.readFully( xmax, 0, n ) ;
        dis.readFully( ymin, 0, n ) ;
        dis.readFully( ymax, 0, n ) ;

    then...convert these byte arrays into integers...(as we did with the nBits array)

    And xmax - xmin SHOULD be equal to the width of the SWF...


    I'd check all this with a hex editor and a pen and paper first though, before you go through the pain of bitwise arithmetic for nothing ;-)

    LVL 1

    Author Comment

    Hi Tim,

    Thanks for your workout and i hope this should be good answer as i am seeing the confidence in writing the solution.

    Sorry for delayed reply, actually i have not got chance to test your code as we are feeding the flash dimension into the database.

    Thank you very much.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    servlet init param and contect param 3 46
    oracle fusion vs MQ 2 77
    countXY challenge 28 93
    instanceof  operator in java 26 57
    Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
    OfficeMate Freezes on login or does not load after login credentials are input.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now