A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Connecting / Buffering Msg's

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    85

    Connecting / Buffering Msg's

    Some of my code may be missing, as it's rather long and I don't want to post it all. Here what I'm trying to do:

    Player opens, says "Connecting to stream.."
    Connection is successful, says "Buffering.."
    Buffer is full, says "metadata.title"

    The first one I simply set the dynamic text field to say connecting. Easy.
    The second one was easy too, I waited for the NetConnection.Connect.Success and then it says "Buffering..".
    The third one I set to read the metadata and display it.

    The problem with my code, is it often goes from step 1 (connecting) to step 3 (the title) without ever seeing "buffering" even with a 5 second buffer. This is because my code displays the title as soon as the metadata is received. 9 times out of 10 the metadata is received first, which results in the buffering message showing up for like 0.01 of a second.

    I tried adding an eventlistener for "NetStream.Buffer.Full" to the ns var but it didn't work. I believe thats what I need to do, but I can't figure it out. Once the buffer is full, the title should appear.. but not before, like it is with the code below.

    Code:
    var nc:NetConnection;
    var ns:NetStream;
    var liveVideo:Video;
    
    //timer for updating player volume
    var tmrDisplay:Timer;
    
    //object holds all meta data
    var objInfo:Object;
    
    liveVideoPlayer.streamTitle.text="Connecting to stream..";
    
    
    nc = new NetConnection();
    
    nc.addEventListener(NetStatusEvent.NET_STATUS, onConnectionStatus);
    
    function onConnectionStatus(e:NetStatusEvent):void {
    	if (e.info.code=="NetConnection.Connect.Success") {
    		getTheStream();
    		liveVideoPlayer.streamTitle.text="Buffering..";
    	}
    }
    
    function getTheStream():void {
    	ns=new NetStream(nc);
    	ns.client=this;
    	liveVideoPlayer.liveVideo.attachNetStream(ns);
    	ns.bufferTime = 5; 
    	ns.play("livestream");
    }
    
    function onMetaData(info:Object):void {
    	if (! tmrDisplay.running) {
    		tmrDisplay.start();
    	}
    
    	objInfo=info;
    
    	liveVideoPlayer.streamTitle.text=info.title;
    }
    
    NetConnection.prototype.onBWDone = function(p_bw) {
    //trace("onBWDone: "+p_bw);
    };
    
    nc.connect("rtmp://12.34.56.789/live");
    Last edited by sufire; 07-26-2009 at 09:09 AM.

  2. #2
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    Well, that's probably because you haven't tested your swf on actual download speed. When you run your SWF it takes no time loading a file, even a big one.

    When your movie is launched, press cntrl+enter / cmnd+enter again and it'll relaunch at a speed you can set (somewhere ) in the menubar of that window

    Or just upload it
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    85
    I have already done that. The problem is that the server usually sends the metadata before sending the audio/video, during buffering. So as soon as it says "buffering", it immediately receives the "title" metadata and replaces it. Thats what I want.. except I want it to wait until the video starts playing. I want people to see "Connecting" for the split-second that it takes to connect (which it already does fine), and then see buffering during the X number of seconds it is buffering for (I set it to 5 for testing). Then, when the video starts playing, switch the text to the metadata title.

    MESSAGE: Connecting..
    ACTION: CONNECT
    MESSAGE: Buffering.. (appears for entire duration of buffer setting, for example, 5 seconds buffer)
    ACTION: STREAM BEGINS TO PLAY
    MESSAGE: My Super Awesome Webcast
    Last edited by sufire; 07-27-2009 at 01:05 AM.

  4. #4
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    You could try adding the same EventListener to the NetStream, as you did for the NetConnection, so you can check for the "NetStream.Buffer.Full" event code:
    PHP Code:
    ns.addEventListener(NetStatusEvent.NET_STATUSonConnectionStatus); 
    And add this inside of that function
    PHP Code:
    if(e.info.code == "NetStream.Play.Start")
    {
       
    liveVideoPlayer.streamTitle.text="Buffering..";
       
    // pause your stream, we want to wait for the buffer to fill
       // add you code here
    }
    else if(
    e.info.code == "NetStream.Buffer.Full")
    {
       
    // do whatever needs to be done
    }

    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center