Hi All,

I've been trying to create a "Buffering" progress bar for streaming
FLV (via FMS) with the <mx:videoDisplay> component. But, the
videoDisplay is not firing "progress" events for some odd reason. So I
changed my strategy and started using the netStream object.

The video is streaming via FMS, but the netStream "bytesLoaded" and
"bytesTotal" properties are always zero. Any ideas what I may be doing
wrong. The code's below. 

Also, it would be great if anyone can show how to pull this of with
the <mx:videoDisplay> component as well!!!

Thanks!
Chris

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; xmlns="*"
layout="vertical" horizontalAlign="left"
creationComplete="onCreationComplete();">
        <mx:Script>
                <![CDATA[
        
//////////////////////////////////////////////////////////////////////////
                import mx.events.VideoEvent;
                import myComponents.*;
                import flash.events.*;
                import flash.net.*;
                import flash.media.Video;
                import mx.controls.*;
                import mx.core.UIComponent;
        
//////////////////////////////////////////////////////////////////////////
                private var nc:NetConnection;
                private var stream:NetStream;
                private var fmsUrl:String;
                private var flvName:String;
                private var video:Video;
                private var loaded_interval:Number;
        
//////////////////////////////////////////////////////////////////////////
                NetConnection.defaultObjectEncoding = 
flash.net.ObjectEncoding.AMF0;
        
//////////////////////////////////////////////////////////////////////////
                public function onCreationComplete():void
                {
                        nc = new NetConnection();
                        configureListeners(nc);
                        
                        var videoHolder:UIComponent = new UIComponent();
                        videoHolder.setActualSize(700, 525);
                        
                        video = new Video();
                        configureListeners(video);
                        
                        videoHolder.addChild(video);
                        video.x = 0;
                        video.y = 0;
                        
                        fmsUrl = "rtmp://localhost/test_video";
                        flvName = "testVideo";
                        theBox.addChild(videoHolder);
                        nc.connect(fmsUrl);
                }
                /////////////////////////////////////////////////////////////
                private function 
configureListeners(dispatcher:IEventDispatcher):void 
                {
                        
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
onSecurityError);
                        
dispatcher.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
                        dispatcher.addEventListener(NetStatusEvent.NET_STATUS, 
onNetStatus);
                        dispatcher.addEventListener(ProgressEvent.PROGRESS, 
onProgress);
                        dispatcher.addEventListener(Event.ENTER_FRAME, 
onEnterFrame);
                }
                /////////////////////////////////////////////////////////////
                private function connectStream():void 
                {
                        if (stream) 
                                stream.close();

                        stream = new NetStream(nc);
                        configureListeners(stream);
                        video.attachNetStream(stream);
                        stream.bufferTime = 10;
                        stream.play(flvName);
                        stream.client = this;
                }
                /////////////////////////////////////////////////////////////
                private function onNetStatus(event:NetStatusEvent):void
                {
                        trace("onNetStatus: " + event);
                        switch (event.info.code) 
                        {
                                 case "NetConnection.Connect.Success":
                                          
trace("NetConnection.Connect.Success");
                                          connectStream();
                                          break;
                                 case "NetConnection.Connect.Failed":
                                          trace("NetConnection.Connect.Failed");
                                          break;
                                 case "NetStream.Buffer.Empty":
                                          trace("NetStream.Buffer.Empty");
                                          break;
                                 case "NetStream.Buffer.Full":
                                          trace("NetStream.Buffer.Full");
                                          break;
                                 case "NetStream.Play.StreamNotFound":
                                          trace("stream not found: " + flvName);
                                          break;
                        }
                }               
                /////////////////////////////////////////////////////////////
                private function onEnterFrame(event:Event):void
                {
                        if(stream == null) return;
                        var loadpct:Number = stream.bytesLoaded / 
stream.bytesTotal * 100;
                        trace("onEnterFrame: " + event + " Loaded: " + loadpct 
+ "%");
                }
                /////////////////////////////////////////////////////////////
                private function onProgress(event:ProgressEvent):void
                {
                        trace("onProgress: " + event);
                }
                /////////////////////////////////////////////////////////////
                private function onSecurityError(event:SecurityErrorEvent):void 
                {
                        trace("onSecurityError: " + event);
                }
                /////////////////////////////////////////////////////////////
                private function onAsyncError(event:AsyncErrorEvent):void 
                {
                        trace("onAsyncError: " + event);
                }
                /////////////////////////////////////////////////////////////
            public function onMetaData(info:Object):void
            {
                        trace("metadata: duration=" + info.duration + " width=" 
+
info.width + " height=" + info.height + " framerate=" + info.framerate);
            }
                /////////////////////////////////////////////////////////////
                public function onCuePoint(info:Object):void
                {
                        trace("cuepoint: time=" + info.time + " name=" + 
info.name + "
type=" + info.type);
                }
                /////////////////////////////////////////////////////////////
                public function showMessage(msg:String):void
                {
                        trace("showMessage: " + msg + "\n");
                }       
                /////////////////////////////////////////////////////////////
                ]]>
        </mx:Script>
        
        <mx:HBox id="theBox" borderStyle="solid"></mx:HBox>
</mx:Application>





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to