Ask a Question related to Adobe Flash, Flex & Director, Design and Development.
-
clsimeone #1
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
-
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... -
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... -
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 =... -
#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: ... -



Reply With Quote


