The following example shows how you can detect when the metadata is received by a Spark VideoPlayer control in Flex 4 by listening for the metadataReceived event.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/05/11/viewing-a-videos-metadata-using-a-spark-videoplayer-control-in-flex-gumbo/ -->
<s:Application name="Spark_VideoPlayer_metadataReceived_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">

    <fx:Script>
        <![CDATA[
            import mx.utils.ObjectUtil;
            import spark.events.VideoEvent;

            private function videoPlayer_metadataReceived(evt:VideoEvent):void {
                debug.text = ObjectUtil.toString(evt.metadataInfo);
            }
        ]]>
    </fx:Script>

    <s:HGroup horizontalCenter="0" verticalCenter="0">
        <s:VideoPlayer id="videoPlayer"
                source="http://helpexamples.com/flash/video/cuepoints.flv"
                muted="true"
                metadataReceived="videoPlayer_metadataReceived(event);" />

        <s:TextArea id="debug"
                editable="false"
                height="{videoPlayer.height}" />
    </s:HGroup>

</s:Application>

View source is enabled in the following example.

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/05/11/viewing-a-videos-metadata-using-a-spark-videoplayer-control-in-flex-gumbo/ -->
<s:Application name="Spark_VideoPlayer_metadataReceived_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        initialize="init();">

    <fx:Script>
        <![CDATA[
            import mx.events.ResizeEvent;
            import mx.utils.ObjectUtil;
            import spark.components.HGroup;
            import spark.components.TextArea;
            import spark.components.VideoPlayer;
            import spark.events.VideoEvent;

            private var videoPlayer:VideoPlayer;
            private var debug:TextArea;

            private function init():void {
                videoPlayer = new VideoPlayer();
                videoPlayer.source = "http://helpexamples.com/flash/video/cuepoints.flv";
                videoPlayer.muted = true;
                videoPlayer.addEventListener(VideoEvent.METADATA_RECEIVED, videoPlayer_metadataReceived);
                videoPlayer.addEventListener(ResizeEvent.RESIZE, videoPlayer_resize);

                debug = new TextArea();
                debug.editable = false;

                var hGr:HGroup = new HGroup();
                hGr.horizontalCenter = 0;
                hGr.verticalCenter = 0;
                hGr.addElement(videoPlayer);
                hGr.addElement(debug);
                addElement(hGr);
            }

            private function videoPlayer_resize(evt:ResizeEvent):void {
                debug.height = videoPlayer.height;
            }

            private function videoPlayer_metadataReceived(evt:VideoEvent):void {
                debug.text = ObjectUtil.toString(evt.metadataInfo);
            }
        ]]>
    </fx:Script>

</s:Application>

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

7 Responses to Viewing a video’s metadata using a Spark VideoPlayer control in Flex 4

  1. SS says:

    Hi Peter,
    How can I escape symbols “” from text Box? I dont wanna allow these symbols to enter to my DB. How can I control them?? Suggest me.
    Thank you

  2. plumento says:

    Could it be, that the current Version of Flex 4 is slightly different? There isn’t any eventListener “metadataReceived”. How can i get the metadata now?

    • Peter deHaan says:

      @plumento,

      Yes, the Spark VideoPlayer component is very different from the MX VideoDisplay component. The new Spark control is based on the new Adobe Open Source Media Framework (OSMF) library. The version of OSMF that shipped with Flex 4.0 (OSMF 0.7) does not include support for metadata or cue points natively, but that support will come later when we update OSMF to a newer version.
      In the meantime, if you need metadata or cue point support, it may be better to stick with the old MX VideoDisplay.

      Peter

  3. daslicht says:

    Hi,
    spark.events.VideoEvent” dont not exist! Using Flex SDK Hero

    • Peter deHaan says:

      @daslicht,

      Unfortunately I don’t think this is currently supported in the Flex 4.x Video components. Previously (Flex 3.x and earlier, and in early Flex 4 betas) the Spark Video controls (s:VideoPlayer and s:VideoDisplay) were based on FLVPlayback code, but in later versions of Flex 4 betas Adobe switched to use the newer Open Source Media Framework (OSMF) APIs.

      Peter

  4. daslicht says:

    I am right on that osmf stuff, even the simpel player is so complex and has so many dependencies that it is hard to follow. :/
    And the cue point example expects a rtmp stream suxx

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree