Working with metadata

You can use the onMetaData method to view the metadata information in your FLV file. Metadata includes information about your FLV file, such as duration, width, height, and frame rate. The metadata information that is added to your FLV file depends on the software you use to encode your FLV file or the software you use to add metadata information.

NOTE

 

If your video file does not have metadata information, you can use tools to add metadata information to the file.

To work with NetStream.onMetaData, you must have Flash Video that contains metadata. If you encode FLV files using Flash 8 Video Encoder, your FLV file will have metadata information in it (see the following example for a list of metadata in a FLV file encoded with Flash 8 Video Encoder).

NOTE

 

Flash Video Exporter 1.2 and later (including Flash 8 Video Exporter), add the metadata to your FLV files. Sorenson Squeeze 4.1 and later also adds metadata to your video files.

The following example uses NetStream.onMetaData to trace the metadata information of an FLV file encoded with Flash 8 Video Encoder.

To use NetStream.onMetaData to view metadata information:

  1. Create a new FLA file called flvMetadata.fla.
  2. In the Library panel (Window > Library), select New Video from the Library
    pop-up menu.
  3. In the Video Properties dialog box, name the video symbol and select Video (ActionScript controlled).
  4. Click OK to create a video object.
  5. Drag the video object from the Library panel to the Stage to create a video object instance.
  6. With the video object selected on the Stage, type my_video in the Instance Name text box in the Property inspector (Window > Properties > Properties).
  7. With the video instance still selected, type 320 in the width text box and 213 in the height text box.
  8. Select Frame 1 in the Timeline, and open the Actions panel (Window > Actions).
  9. Type the following code in the Actions panel:
    // Create a NetConnection object.
    var netConn:NetConnection = new NetConnection();
    // Create a local streaming connection.
    netConn.connect(null);
    // Create a NetStream object and define an onStatus() function.
    var nStream:NetStream = new NetStream(netConn);
    // Attach the NetStream video feed to the Video object.
    my_video.attachVideo(nStream);
    // Set the buffer time.
    nStream.setBufferTime(30);
    // Being playing the FLV file.
    nStream.play("http://www.helpexamples.com/flash/video/lights_short.flv");
    // Trace the metadata.
    nStream.onMetaData = function(myMeta) { 
         for (var i in myMeta) { 
              trace(i + ":\t" + myMeta[i]) 
         } 
    };
    
  10. Select Control > Test Movie to test your code.

    You see the following information in the Output panel:

    canSeekToEnd:    true
    audiocodecid:    2
    audiodelay:    0.038
    audiodatarate:    96
    videocodecid:    4
    framerate:    15
    videodatarate:    400
    height:    213
    width:    320
    duration:    8.04
    

    NOTE

     

    If your video does not have audio, the audio-related metadata information (such as audiodatarate) returns undefined because no audio information is added to the metadata during encoding.

You can also use the following format to display most metadata information. For example, the following code shows the duration of an FLV file:

nStream.onMetaData = function(myMeta) {
    trace("FLV duration: " + myMeta.duration + " sec.");
};

This format cannot trace cuePoint metadata information. For information on tracing cue points, see Tracing cue points from an FLV file.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001039.html