2 Replies Latest reply on Jun 22, 2007 12:14 PM by phi2265

    VideoDisplay

    frenchi30 Level 1
      hello,

      In flash, the FLVPlayback component comes with a scrubber and progress bar. But in Flex the VideoDisplay does not, or at least it appears that way.
      How do I create an FLV player with scrub/progress bar in Flex?
      Any help is appreaciated,

      thank-you
        • 1. Re: VideoDisplay
          frenchi30 Level 1
          Anyone? Please

          It looks like I will have to create one from scratch, any examples?

          thank-you
          • 2. Re: VideoDisplay
            phi2265
            <!--MXML File-->

            <mx:NumberFormatter id="position_fmt" precision="3" />

            <mx:Canvas y="15" width="360" height="285" verticalScrollPolicy="off" horizontalScrollPolicy="off">
            <mx:VideoDisplay id="Vid" source="{vidFileURL}" width="352" height="240" x="5" y="0" creationComplete="Vid.pause();"/>
            <mx:Button id="VidPause" label="Pause" click="Vid.pause();" x="260" y="260" color="#000000"/>
            <mx:Button id="VidPlay" label="Play" click="Vid.play();" x="200" y="260" color="#000000"/>
            <mx:ProgressBar id="vidProgress" x="23" y="243" width="335" mode="manual" source="Vid" indeterminate="true"/>
            <mx:HSlider id="vidSlider" x="16" y="234" width="347"
            minimum="0"
            maximum="{Vid.totalTime}"
            liveDragging="false"
            value="{Vid.playheadTime}"
            thumbPress="hsliderPressHandler(event);"
            thumbRelease="hsliderReleaseHandler(event);"
            change="hsliderChangeHandler(event);"/>
            </mx:Canvas>

            // ActionScript file
            import flash.events.Event;
            import flash.net.URLLoader;
            import flash.display.Loader;
            import flash.net.URLRequest;
            import mx.events.SliderEvent;
            import flash.errors.IOError;
            import flash.events.IOErrorEvent;
            import flash.media.Video;
            import flash.utils.Timer;
            import flash.events.TimerEvent;

            NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
            SharedObject.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;



            public var vidFile:Loader = new Loader();
            [Bindable]
            public var vidFileURL:String = new String("videos/construction.flv");
            public var vidFileURLReq:URLRequest;
            private var wasPlaying:Boolean = false;
            public var counter:int = 0;
            public var startstoptimer:Timer = new Timer(1000);


            public function videoInit():void{
            videoLoader();
            }

            public function vidStartStop():void{
            startstoptimer.addEventListener(TimerEvent.TIMER, startstopHandler);
            startstoptimer.start();
            }

            private function startstopHandler(event:TimerEvent):void{
            counter++;
            if (counter==2){
            Vid.pause();
            startstoptimer.stop();
            }
            }

            public function videoLoader():void{
            Vid.autoPlay=true;
            vidProgress.setProgress(0,100);
            vidProgress.visible=true;
            vidProgress.indeterminate=true;
            vidFileURLReq = new URLRequest(vidFileURL);
            vidFile.load(vidFileURLReq);
            vidFile.contentLoaderInfo.addEventListener(Event.OPEN, vidOpenHandler);
            vidFile.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, vidProgressHandler);
            vidFile.contentLoaderInfo.addEventListener(Event.COMPLETE, vidLoadCompleteHandler);
            vidFile.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
            vidStartStop();
            }

            private function errorHandler(errorEvent:IOErrorEvent):void{

            }

            private function vidOpenHandler(event:Event):void{
            vidProgress.indeterminate=false;
            }

            private function vidProgressHandler(event:ProgressEvent):void{
            vidProgress.setProgress(event.bytesLoaded,event.bytesTotal);
            }

            private function vidLoadCompleteHandler(event:Event):void{

            }

            private function hsliderPressHandler(evt:SliderEvent):void {
            wasPlaying = this.Vid.playing;
            if(wasPlaying) {
            this.Vid.pause();
            }
            }

            private function hsliderReleaseHandler(evt:SliderEvent):void {
            if(wasPlaying) {
            this.vidSlider.callLater(this.Vid.play);
            }
            }

            private function playVid():void{
            this.Vid.play();
            }

            private function hsliderChangeHandler(evt:SliderEvent):void {
            this.Vid.playheadTime = Number(this.position_fmt.format(evt.value));
            }

            There's some of my code.. the MXML and the AS file. That works.