views:

34

answers:

1

I'm creating a video player in an environment where stream.bytesTotal isn't available. I need to use the duration metadata encoded in flv files to extrapolate for things such as the play progress, and the time display.

The problem is when loading an flv the metadata, including the duration, fails to be accessed 2 out of 3 times. Here is the function that iterates through the metadata object :-

public function onMetaDataHandler(metadataObj:Object):void {

for (var metadata:Object in metadataObj) {

    if (metadata == "duration" ) {

        _duration = metadataObj[metadata];

        Debug.log('metadata _duration == ' + _duration );

        playBackTimeText();

    }

    if (metadata == "width" ) {

        video.width = metadataObj[metadata];
    }

    if (metadata == "height" ) {

        video.height = metadataObj[metadata];
    }

    Debug.log(metadata + ": " + metadataObj[metadata], 0xffff00);

}

}

Is this the best way to do this, or is there a way to reload metadata without reloading the flv?

A: 

I'm not sure why but it looks like setting the onMetaData function as a direct callback has solved the issue. I don't think It's as elegant but it works..

   client = new Object();

   client.onMetaData = function (metadataObj:Object):void {

                for (var metadata:Object in metadataObj) {

                    if (metadata == "duration" ) {

                        _duration = metadataObj[metadata];

                        Debug.log('metadata _duration == ' + _duration );

                        playBackTimeText();                 
                    }

                    if (metadata == "width" ) {

                        video.width = metadataObj[metadata];
                    }

                    if (metadata == "height" ) {

                        video.height = metadataObj[metadata];
                    }

                    Debug.log(metadata + ": " + metadataObj[metadata], 0xffff00);                   
                }

            }

        client.cuepoint = onCuePoint;

        _stream.client = client;
martin