Skip to content

Instantly share code, notes, and snippets.

@aerith
Created November 17, 2010 15:10
Show Gist options
  • Save aerith/703478 to your computer and use it in GitHub Desktop.
Save aerith/703478 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" minHeight="400" creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.VideoEvent;
import mx.events.SliderEvent;
private var playheadTimeSliderDragging:Boolean = false;
private function creationCompleteHandler(event:Event):void
{
flv.addEventListener(VideoEvent.PLAYHEAD_UPDATE, playheadUpdateHandler);
playtimeSlider.addEventListener(SliderEvent.CHANGE, timeChangeHandler);
playtimeSlider.addEventListener(SliderEvent.THUMB_PRESS, playheadTimeSliderPressHandler);
playtimeSlider.addEventListener(SliderEvent.THUMB_RELEASE, playheadTimeSliderReleaseHandler);
volumeSlider.addEventListener(SliderEvent.CHANGE, volumeChangeHandler);
}
private function playheadUpdateHandler(event:VideoEvent):void
{
if (!playheadTimeSliderDragging) {
playtimeSlider.value = flv.playheadTime;
}
}
private function timeChangeHandler(event:SliderEvent):void
{
if (!playheadTimeSliderDragging) {
flv.playheadTime = playtimeSlider.value;
}
}
private function playheadTimeSliderPressHandler(event:SliderEvent):void
{
playheadTimeSliderDragging = true;
}
private function playheadTimeSliderReleaseHandler(event:SliderEvent):void
{
flv.playheadTime = playtimeSlider.value;
playheadTimeSliderDragging = false;
}
private function volumeChangeHandler(event:SliderEvent):void
{
flv.volume = volumeSlider.value;
}
public function fixTime(value:Number):String
{
return (value / 60).toFixed(2).toString();
}
]]>
</fx:Script>
<mx:Canvas>
<mx:VBox>
<mx:VideoDisplay id="flv" width="400" height="250" autoRewind="true" autoPlay="false" source="assets/movie/sample.flv" />
<mx:HBox>
<mx:Button id="startButton" click="{flv.playing ? flv.pause() : flv.play()}" label="{flv.playing ? '□' : '>'}" width="26" />
<mx:Button id="stopButton" click="{flv.stop()}" label="-" width="26" />
<mx:HSlider id="playtimeSlider" minimum="0" maximum="{flv.totalTime}" value="0" width="150" />
<mx:Text id="playTimeText" text="{fixTime(flv.playheadTime)} / {fixTime(flv.totalTime)}" />
<mx:HSlider id="volumeSlider" minimum="0" maximum="1" value="{flv.volume}" width="100" />
</mx:HBox>
</mx:VBox>
</mx:Canvas>
</s:Application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment