I am a frontend developer and author based in the UK, specializing in JavaScript development and application architecture. I founded Newtriks Ltd. and have been remotely contracting for the last 10 years for global corporations and venture-backed start-ups. I regularly consult Angular, Backbone, and React, and train programmers in test-driven development. I'm an enthusiastic open source contributor and am the cofounder and lead developer of the live webcasting platform Sayansho Ltd. Please contact me to discuss your specific business requirements.
A Flex Video Scrubber Using HSlider
I have noticed there are not to many resources for building a scrubber to use in a custom Flex video application. I have noticed a great start located here at Flex Examples for use with the VideoDisplay control, however, I tend to create a class that extends UIComponent and pops in a Video Object. So in comparison to the above tutorial I track playhead time and length of flv content from the NetStream and MetaData. So in a nut shell here is a simplified version of how I built the scrubber, this is snatch and grab code from my player so has elements of the framework I use (PureMVC), I will work on a simple demo in another post yo:
Main workflow is:
+ HSlider thumb value changes according to the current NetStream time using a Timer event
+ HSlider thumb pressed and NetStream paused, Timer reset
+ HSlider thumb released and NetStream seeks to HSlider release point value
+ Timer restarted and NetStream start play
HSlider component
123456789101112
<mx:Metadata>
[Event("press")]
[Event("release")]
</mx:Metadata>
<mx:Script>
<![CDATA[
public static const PRESS:String = "press";
public static const RELEASE:String = "release";
]]>
</mx:Script>
Class receiving dispatched events from Hslider component
1234567891011121314151617181920212223242526
private function setDuration():void
{
avHolder.scrubber.minimum = 0;
avHolder.scrubber.maximum = meta.duration;
}
private function trackProgress( ns_time:Number ):void
{
// Dispatched current time value of the net streams play position
avHolder.scrubber.value = ns_time;
}
// Started scrubbing so pause the stream
private function onScrubStart( e:Event ):void
{
sendNotification( ApplicationFacade.CONTROL_STREAM, "pause" );
}
// Tell the class handling the nest stream what the time value of the scrubber was on release
private function onScrubStop( e:Event ):void
{
var scrubTime:Number = avHolder.scrubber.value;
sendNotification( ApplicationFacade.SCRUB, scrubTime );
}
Class handling Net Stream
1234567891011121314151617181920212223242526272829
// This method is called every 10 ms using the Timer class
public function scrubStream( scrubTime:Number ):void
{
// Scrubber moved and released
ns.seek( scrubTime );
// Rebuild the timer
buildDurationTimer();
// Start playing stream
ns.togglePause();
}
// Called when the scrubber is pressed, ensures the timer is removed and the stream is paused
public function pauseStream():void
{
ns.pause();
resetTimer();
}
public function resetTimer():void
{
t.stop();
t.reset();
t.removeEventListener( TimerEvent.TIMER, timerHandler );
}
public function toggleStream():void
{
ns.togglePause();
}