Buffer progress bar for streaming FLV

Ask a Question related to Adobe Flash, Flex & Director, Design and Development.

  1. #1

    Default Buffer progress bar for streaming FLV

    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):vo id
    {
    dispatcher.addEventListener(SecurityErrorEvent.SEC URITY_ERROR,
    onSecurityError);
    dispatcher.addEventListener(AsyncErrorEvent.ASYNC_ ERROR, onAsyncError);
    dispatcher.addEventListener(NetStatusEvent.NET_STA TUS, 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>

    clsimeone Guest

  2. Similar Questions and Discussions

    1. Buffer Progress Bar
      I have a streaming Flv and I need a buffer progress bar for it. I'm new to action script and to streaming. I often take tutorials and adapt them to...
    2. FLV Buffer Progress Bar
      Hi guys... As many people i?m having troubles to make a loading/progress bar for the buffer. I Can make a progress bar to indicate the current...
    3. dbaccess buffer
      In dbaccess (for me, Informix 7.31), if I have the following statements: set lock mode to wait; update table set column = 'X' where columnPK =...
    4. #25217 [NEW]: calling ob_gzhandler after modified buffer in ob handler, return origin buffer
      From: Xuefer at 21cn dot com Operating system: win PHP version: 4.3.3RC4 PHP Bug Type: Output Control Bug description: ...
  3. #2

    Default Re: Buffer progress bar for streaming FLV

    nth wrong, just for streaming you need to use netStream.bufferTime and bufferLenght properties

    Quote Originally Posted by clsimeone View Post
    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):vo id
    {
    dispatcher.addEventListener(SecurityErrorEvent.SEC URITY_ERROR,
    onSecurityError);
    dispatcher.addEventListener(AsyncErrorEvent.ASYNC_ ERROR, onAsyncError);
    dispatcher.addEventListener(NetStatusEvent.NET_STA TUS, 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>
    Unregistered Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139