<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; playheadUpdate</title>
	<atom:link href="http://blog.flexexamples.com/tag/playheadupdate/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Determining when a video has finished playing in a Spark VideoPlayer control in Flex 4</title>
		<link>http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/</link>
		<comments>http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/#comments</comments>
		<pubDate>Wed, 13 May 2009 06:59:39 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[beta1]]></category>
		<category><![CDATA[VideoPlayer (Spark)]]></category>
		<category><![CDATA[autoRewind]]></category>
		<category><![CDATA[complete]]></category>
		<category><![CDATA[Gumbo]]></category>
		<category><![CDATA[playheadUpdate]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/</guid>
		<description><![CDATA[<p>The following example shows how you can determine when a video has finished playing in a Spark VideoPlayer control in Flex 4 by listening for the complete event.</p> <p>Full code after the jump.</p> <p></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/ --&#62; &#60;s:Application name="Spark_VideoPlayer_complete_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"&#62; &#60;fx:Script&#62; &#60;![CDATA[ import spark.events.VideoEvent; private function videoPlayer_playheadUpdate(evt:VideoEvent):void { var now:String [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can determine when a video has finished playing in a Spark VideoPlayer control in Flex 4 by listening for the <code>complete</code> event.</p>
<p>Full code after the jump.</p>
<p><span id="more-1077"></span></p>
<p class="alert">The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see <a href="http://bit.ly/crThlI">http://www.adobe.com/products/flex/</a>. To download the latest nightly build of the Flex 4 SDK, see <a href="http://bit.ly/Flex4SDK">http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4</a>.<br/><strong>For more information on getting started with Flex 4 and Flash Builder 4, see the official <a href="http://bit.ly/dCkecm">Adobe Flex Team blog</a>.</strong></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/ --&gt;
&lt;s:Application name="Spark_VideoPlayer_complete_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"&gt;

    &lt;fx:Script&gt;
        &lt;![CDATA[
            import spark.events.VideoEvent;

            private function videoPlayer_playheadUpdate(evt:VideoEvent):void {
                var now:String = new Date().toLocaleTimeString();
                debug.appendText(evt.type + " -- " + now + "\\n");
            }
        ]]&gt;
    &lt;/fx:Script&gt;

    &lt;s:HGroup horizontalCenter="0" verticalCenter="0"&gt;
        &lt;s:VideoPlayer id="videoPlayer"
                source="http://helpexamples.com/flash/video/water.flv"
                autoRewind="true"
                muted="true"
                playheadUpdate="videoPlayer_playheadUpdate(event);"
                complete="videoPlayer_playheadUpdate(event);" /&gt;
        &lt;s:TextArea id="debug"
                editable="false"
                height="{videoPlayer.height}"
                verticalScrollPolicy="on" /&gt;
    &lt;/s:HGroup&gt;

&lt;/s:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/spark/Spark_VideoPlayer_complete_test/bin/srcview/">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/spark/Spark_VideoPlayer_complete_test/bin/main.html" width="100%" height="350"></iframe></p>
<p>Due to popular demand, here is the &#8220;same&#8221; example in a more ActionScript friendly format:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/ --&gt;
&lt;s:Application name="Spark_VideoPlayer_complete_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();"&gt;

    &lt;fx:Script&gt;
        &lt;![CDATA[
            import mx.core.ScrollPolicy;
            import mx.events.ResizeEvent;
            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/water.flv";
                videoPlayer.autoRewind = true;
                videoPlayer.muted = true;
                videoPlayer.addEventListener(ResizeEvent.RESIZE, videoPlayer_resize);
                videoPlayer.addEventListener(VideoEvent.PLAYHEAD_UPDATE, videoPlayer_playheadUpdate);
                videoPlayer.addEventListener(VideoEvent.COMPLETE, videoPlayer_playheadUpdate);

                debug = new TextArea();
                debug.editable = false;
                debug.verticalScrollPolicy = ScrollPolicy.ON;

                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_playheadUpdate(evt:VideoEvent):void {
                var now:String = new Date().toLocaleTimeString();
                debug.appendText(evt.type + " -- " + now + "\\n");
            }
        ]]&gt;
    &lt;/fx:Script&gt;

&lt;/s:Application&gt;
</pre>
<p class="alert">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.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Determining when a video has finished playing in a Spark VideoPlayer control in Flex 4 on FlexExamples.com',url: 'http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/',contentID: 'post-1077',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'autoRewind,complete,Gumbo,playheadUpdate',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2009/05/12/determining-when-a-video-has-finished-playing-in-a-spark-videoplayer-control-in-flex-gumbo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scrubbing an FLV using the VideoDisplay control and a slider</title>
		<link>http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/</link>
		<comments>http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 15:04:00 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DateFormatter]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<category><![CDATA[allowTrackClick]]></category>
		<category><![CDATA[invertThumbDirection]]></category>
		<category><![CDATA[playheadUpdate]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/</guid>
		<description><![CDATA[<p>In yet *another* post about the VideoDisplay control, this time we look at formatting playback times using the DateFormatter class/tag, creating a basic scrubber using an HSlider control, and applying a mildly annoying Zoom effect to the video.</p> <p>Also, we tweak the slider control (or more accurately HSlider) and prevent users from clicking on the [...]]]></description>
			<content:encoded><![CDATA[<p>In yet *another* post about the VideoDisplay control, this time we look at formatting playback times using the DateFormatter class/tag, creating a basic scrubber using an HSlider control, and applying a mildly annoying Zoom effect to the video.</p>
<p>Also, we tweak the slider control (or more accurately HSlider) and prevent users from clicking on the slider track (thanks to the <code>allowTrackClick</code> property, we set the <code>liveDragging</code> property to false to make sure we arent needlessly seeking around the video every time the slider thumb moves, and finally we invert the thumb arrow for no other reason than I didn&#8217;t know you could do that so easily.</p>
<p>Oh, and I also created a faux looping video by using the <code>autoRewind</code> property, and calling the <code>play()</code> method in the <code>rewind</code> event handler.</p>
<p>Full code after the jump.</p>
<p><span id="more-46"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/DateFormatter_format_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function formatTime(item:Date):String {
                return dateFormatter.format(item);
            }

            private function videoDisplay_playheadUpdate():void {
                /* If playhead time is 0, set to 100ms so the DateFormatter doesnt return an empty string. */
                var pT:Number = videoDisplay.playheadTime || 0.1;
                var tT:Number = videoDisplay.totalTime;

                /* Convert playheadTime and totalTime from seconds to milliseconds and create new Date objects. */
                var pTimeMS:Date = new Date(pT * 1000);
                var tTimeMS:Date = new Date(tT * 1000);

                timeLabel.text = formatTime(pTimeMS) + " / " + formatTime(tTimeMS);
            }

            private function slider_thumbPress():void {
                videoDisplay.pause();
            }

            private function slider_thumbRelease():void {
                videoDisplay.playheadTime = slider.value;
                videoDisplay.play();
            }

            private function videoDisplay_ready():void {
                videoDisplay.visible = true;
                controlBar.visible = true;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;!-- Only show minutes and seconds. --&gt;
    &lt;mx:DateFormatter id="dateFormatter" formatString="NN:SS" /&gt;

    &lt;mx:Zoom id="zoom" /&gt;

    &lt;mx:Panel title="{videoDisplay.source.split('/').pop()} ({videoDisplay.state})"&gt;
        &lt;mx:VideoDisplay id="videoDisplay" visible="false" showEffect="{zoom}"
            playheadUpdate="videoDisplay_playheadUpdate()"
            ready="videoDisplay_ready()"
            rewind="videoDisplay.play()"
            source="http://www.helpexamples.com/flash/video/cuepoints.flv" /&gt;

        &lt;mx:ControlBar id="controlBar" visible="false"&gt;
            &lt;mx:HSlider id="slider" width="100%"
                allowTrackClick="false"
                invertThumbDirection="true"
                liveDragging="false"
                maximum="{videoDisplay.totalTime}"
                minimum="0"
                thumbPress="slider_thumbPress()"
                thumbRelease="slider_thumbRelease()"
                tickInterval="1"
                value="{videoDisplay.playheadTime}" /&gt;
            &lt;mx:Label id="timeLabel" textAlign="right" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information">View source enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/DateFormatter_format_test/bin/main.html" width="100%" height="400"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Scrubbing an FLV using the VideoDisplay control and a slider on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/',contentID: 'post-46',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'allowTrackClick,invertThumbDirection,playheadUpdate',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/02/scrubbing-an-flv-using-the-videodisplay-control-and-a-slider/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Creating ActionScript cue points with the VideoDisplay control</title>
		<link>http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/</link>
		<comments>http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 06:00:32 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[CuePointEvent]]></category>
		<category><![CDATA[VideoDisplay]]></category>
		<category><![CDATA[cuePoint]]></category>
		<category><![CDATA[cuePointManagerClass]]></category>
		<category><![CDATA[playheadUpdate]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/</guid>
		<description><![CDATA[<p>A simple example of creating and using ActionScript cue points with the VideoDisplay control. The example uses a VideoDisplay control to display the progressively downloaded video, a ProgressBar to display the amount of video that has played back, and two DataGrid controls to show ActionScript cue points and embedded cue points.</p> <p>Full code after the [...]]]></description>
			<content:encoded><![CDATA[<p>A simple example of creating and using ActionScript cue points with the VideoDisplay control. The example uses a VideoDisplay control to display the progressively downloaded video, a ProgressBar to display the amount of video that has played back, and two DataGrid controls to show ActionScript cue points and embedded cue points.</p>
<p>Full code after the jump.</p>
<p><span id="more-39"></span></p>
<p>The following example creates a series of ActionScript cue points using the &lt;mx:Array&gt; tag and adds them to the VideoDisplay control by setting its <code>cuePoints</code> property. It also demonstrates how you can use a ProgressBar control to display the video playback status using the <code>playheadUpdate</code> event and the ProgressBar control&#8217;s <code>label</code> property:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.CuePointEvent;

            [Bindable]
            private var embeddedCuePoints:ArrayCollection = new ArrayCollection();

            private function onCuePoint(evt:CuePointEvent):void {
                var cuePointObject:Object = {name:evt.cuePointName, time:evt.cuePointTime, type:evt.cuePointType};
                if (evt.cuePointType != "actionscript") {
                    embeddedCuePoints.addItem(cuePointObject);
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Array id="cuePointArr"&gt;
        &lt;mx:Object name="one" time="1" type="actionscript" /&gt;
        &lt;mx:Object name="two" time="2" type="actionscript" /&gt;
    &lt;/mx:Array&gt;

    &lt;mx:VideoDisplay id="videoDisplay" cuePointManagerClass="mx.controls.videoClasses.CuePointManager" cuePoints="{cuePointArr}" cuePoint="onCuePoint(event)" source="http://www.helpexamples.com/flash/video/cuepoints.flv" playheadUpdate="progressBar.setProgress(videoDisplay.playheadTime, videoDisplay.totalTime);" /&gt;
    &lt;mx:ProgressBar id="progressBar" mode="manual" width="{videoDisplay.width}" minimum="0" maximum="{videoDisplay.totalTime}" label="{videoDisplay.state} %3%%" /&gt;

    &lt;mx:HBox&gt;
        &lt;mx:Panel title="ActionScript cue points:"&gt;
            &lt;mx:DataGrid id="actionScriptCuePointGrid" dataProvider="{videoDisplay.cuePoints}"&gt;
                &lt;mx:columns&gt;
                    &lt;mx:DataGridColumn dataField="name" headerText="Name:" /&gt;
                    &lt;mx:DataGridColumn dataField="time" headerText="Time:" /&gt;
                    &lt;mx:DataGridColumn dataField="type" headerText="Type:" /&gt;
                &lt;/mx:columns&gt;
            &lt;/mx:DataGrid&gt;
        &lt;/mx:Panel&gt;

        &lt;mx:Panel title="Embedded cue points:"&gt;
            &lt;mx:DataGrid id="embeddedCuePointGrid" dataProvider="{embeddedCuePoints}" itemClick="videoDisplay.playheadTime = event.currentTarget.selectedItem.time;"&gt;
                &lt;mx:columns&gt;
                    &lt;mx:DataGridColumn dataField="name" headerText="Name:" /&gt;
                    &lt;mx:DataGridColumn dataField="time" headerText="Time:" /&gt;
                    &lt;mx:DataGridColumn dataField="type" headerText="Type:" /&gt;
                &lt;/mx:columns&gt;
            &lt;/mx:DataGrid&gt;
        &lt;/mx:Panel&gt;
    &lt;/mx:HBox&gt;

&lt;/mx:Application&gt;</pre>
<p>If you prefer to define the cue point array in ActionScript rather than MXML, you could use this snippet instead:</p>
<pre class="code">
[Bindable]
private var cuePointArr:Array = [{name:"one", time:1, type:"actionscript"}, {name:"two", time:2, type:"actionscript"}];
</pre>
<p>Or&#8230;</p>
<pre class="code">
[Bindable]
private var cuePointArr:Array;

private function initCuePoints():void {
    cuePointArr = new Array();
    cuePointArr.push({name:"one", time:1, type:"actionscript"});
    cuePointArr.push({name:"two", time:2, type:"actionscript"});
    videoDisplay.cuePoints = cuePointArr;
}
</pre>
<p>You can also define the ActionScript cue points directly within the VideoDisplay MXML tags, like so:</p>
<pre class="code">
&lt;mx:VideoDisplay id="videoDisplay" cuePointManagerClass="mx.controls.videoClasses.CuePointManager" cuePoint="onCuePoint(event)" source="http://www.helpexamples.com/flash/video/cuepoints.flv" playheadUpdate="progressBar.setProgress(videoDisplay.playheadTime, videoDisplay.totalTime);"&gt;
    &lt;mx:cuePoints&gt;
        &lt;mx:Object name="one" time="1" type="actionscript" /&gt;
        &lt;mx:Object name="two" time="2" type="actionscript" /&gt;
    &lt;/mx:cuePoints&gt;
&lt;/mx:VideoDisplay&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating ActionScript cue points with the VideoDisplay control on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/',contentID: 'post-39',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'cuePoint,cuePointManagerClass,playheadUpdate',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/07/29/creating-actionscript-cue-points-with-the-videodisplay-control/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

