Setting the playhead update interval on the Spark VideoPlayer control in Flex 4

The following example shows how you cna set the playhead update interval on a Spark VideoPlayer control in Flex 4 by setting the playheadUpdateInterval property on the VideoPlayer object’s internal VideoElement object using the mx_internal namespaced fl.video.VideoPlayer object.

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see 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/23/setting-the-playhead-update-interval-on-the-spark-videoplayer-control-in-flex-gumbo/ -->
<s:Application name="Spark_VideoPlayer_VideoElement_flVideoPlayer_playheadUpdateInterval_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 fl.video.VideoPlayer;
            import spark.events.VideoEvent;

            private function videoPlayer_metadataReceived(evt:VideoEvent):void {
                videoPlayer.videoElement.mx_internal::videoPlayer.playheadUpdateInterval = 3000;
            }

            private function videoPlayer_playheadUpdate(evt:VideoEvent):void {
                arrList.addItem({type:evt.type, time:evt.playheadTime.toFixed(2)});
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <s:ArrayList id="arrList" />
    </fx:Declarations>

    <s:Panel id="panel"
            horizontalCenter="0"
            verticalCenter="0">
        <s:layout>
            <s:HorizontalLayout />
        </s:layout>
        <s:VideoPlayer id="videoPlayer"
                source="http://helpexamples.com/flash/video/cuepoints.flv"
                muted="true"
                metadataReceived="videoPlayer_metadataReceived(event);"
                playheadUpdate="videoPlayer_playheadUpdate(event);" />
        <mx:DataGrid id="dataGrid"
                dataProvider="{arrList}"
                height="100%"
                verticalScrollPolicy="on">
            <mx:columns>
                <mx:DataGridColumn dataField="type" width="140" />
                <mx:DataGridColumn dataField="time" width="60" />
            </mx:columns>
        </mx:DataGrid>
    </s:Panel>

</s:Application>

View source is enabled in the following example.

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.