Closed GoogleCodeExporter closed 9 years ago
That can not work. Ever.
First, Pyro proxies all event broadcasting for you, in 99.9 percent of the
time, while using Pyro, all you need to
do is to register to the PyroEvent event and the StatusUpdateEvent event.
The point of Pyro is that you dont have to go thru that routine of tracing
NetStatusEvent, I have rarely seen
cases where we had to play inside the NetStatusEvent callbacks.
For exemple we use things like this:
pyroInstance.addEventListener(StatusUpdateEvent.STATUS_UPDATE, statusUpdated);
function statusUpdated(evt: StatusUpdateEvent):void
{
// All possible statuses are set as constants of the Pyro class.
// ex: Pyro.STATUS_STOPPED
// the following have identical results.
trace (evt.status);
trace (pyroInstance.status);
}
Same dynamic goes for all events used by Pyro, just look inside the events
folder.
I do not recommend using direct use of the netStream instance pyro uses,
however you can probably do it like
this, but you'll have to wait for pyro to be fully initialized.
pyroInstance.netStream.addEventListener(NetStatusEvent.NET_STATUS,
statusFunction);
I strongly suggest you not to do this and to use pyro's built in features.
Hope that answers your question. If not, please elaborate on what you need to
do and I'll guide you thru.
Cheers,
reech me at:
nibman@gmail.com
e@gronour.com
Eric
Original comment by nib...@gmail.com
on 4 Jul 2009 at 8:42
You probably tried
pyroInstance.netStream.addEventListener(NetStatusEvent.NET_STATUS,
statusFunction);
and found it did not work or threw errors, thats because you cannot register to
the netStream instance if it
has not been created yet.
You could however extend Pyro with one of your class and override the
netStausHandling (I do not recommend
it, unless you know what you are doing, since the handling is crucial to Pyro's
inner workings).
Here is the function you would need to override.
protected function onStreamStatus(evt:NetStatusEvent):void
{
switch (evt.info.code)
{
case "NetStream.Pause.Notify":
if (_status != Pyro.STATUS_PAUSED)
{
dispatchEvent(new PyroEvent(PyroEvent.PAUSED, bubbleEvents, cancelableEvents));
setStatus(Pyro.STATUS_PAUSED);
}
break;
case "NetStream.Buffer.Empty":
if (autoAdjustBufferTime)
{
if (_bufferEmptiedOccurences >= bufferEmptiedMaxOccurences)
{
switch (connectionSpeed)
{
case Pyro.CONNECTION_SPEED_HIGH:
_connectionSpeed = Pyro.CONNECTION_SPEED_MEDIUM;
adjustBufferTimes(_mediumSpeedBufferTable);
_bufferEmptiedOccurences = 0;
this.dispatchEvent(new PyroEvent(PyroEvent.BUFFER_TIME_ADJUSTED,
bubbleEvents, cancelableEvents));
break;
case Pyro.CONNECTION_SPEED_MEDIUM:
_connectionSpeed = Pyro.CONNECTION_SPEED_LOW;
adjustBufferTimes(_lowSpeedBufferTable);
_bufferEmptiedOccurences = 0;
this.dispatchEvent(new PyroEvent(PyroEvent.BUFFER_TIME_ADJUSTED,
bubbleEvents, cancelableEvents));
break;
case Pyro.CONNECTION_SPEED_LOW:
_bufferEmptiedOccurences = 0;
_lowSpeedBufferTable.singleTresholdBufferTime +=
_lowSpeedBufferTable.singleTresholdBufferTime*.1;
_lowSpeedBufferTable.dualTresholdStartBufferTime +=
_lowSpeedBufferTable.dualTresholdStartBufferTime*.1;
this.dispatchEvent(new PyroEvent(PyroEvent.INSUFFICIENT_BANDWIDTH,
bubbleEvents, cancelableEvents));
break;
}
}
else
{
_bufferEmptiedOccurences++;
}
}
if (this.bufferingMode == Pyro.BUFFERING_MODE_DUAL_TRESHOLD)
this._nStream.bufferTime = this._dualStartBufferTime;
dispatchEvent(new PyroEvent(PyroEvent.BUFFER_EMPTY, bubbleEvents,
cancelableEvents));
break;
case "NetStream.Buffer.Full":
if (firstRun)
{
if (autoPlay)
{
this.setStatus(Pyro.STATUS_PLAYING);
firstRun = false;
}
}
dispatchEvent(new PyroEvent(PyroEvent.BUFFER_FULL, bubbleEvents, cancelableEvents));
var currentBufferTable:BufferTimeTable;
if (checkBandwidth && !bandwidthCheckDone)
{
var userBandwidth:Number;
var connTime:Number = getTimer() - startTime;
userBandwidth = (bufferLength * (streamDataRate) / (connTime/1000));
/* var connTime:Number = getTimer() - startTime;
var userBandwidth:Number = ((1000 * _nStream.bytesLoaded) / connTime) / 1024;
var buffer:Number = getBandwidth(_duration, streamDataRate, userBandwidth); */
if (userBandwidth <= 60)
{
_connectionSpeed = Pyro.CONNECTION_SPEED_LOW;
currentBufferTable = _lowSpeedBufferTable;
bufferEmptiedMaxOccurences = 3;
}
else
{
if (userBandwidth > 60 && userBandwidth <= 120)
{
bufferEmptiedMaxOccurences = 2;
currentBufferTable = _mediumSpeedBufferTable;
_connectionSpeed = Pyro.CONNECTION_SPEED_MEDIUM;
}
else if (userBandwidth > 120)
{
bufferEmptiedMaxOccurences = 1;
currentBufferTable = _highSpeedBufferTable;
_connectionSpeed = Pyro.CONNECTION_SPEED_HIGH;
}
}
if (autoAdjustBufferTime)
adjustBufferTimes(currentBufferTable);
dispatchEvent(new PyroEvent(PyroEvent.BANDWIDTH_CHECKED, bubbleEvents,
cancelableEvents));
bandwidthCheckDone = true;
}
if (this.bufferingMode == Pyro.BUFFERING_MODE_DUAL_TRESHOLD)
_nStream.bufferTime = _dualStartBufferTime;
break;
case "NetStream.Buffer.Flush":
flushed = true;
dispatchEvent(new PyroEvent(PyroEvent.BUFFER_FLUSH, bubbleEvents, cancelableEvents));
break;
case "NetStream.Play.Complete":
if (status != Pyro.STATUS_COMPLETED)
{
_status = Pyro.STATUS_COMPLETED;
dispatchEvent(new PyroEvent(PyroEvent.COMPLETED, bubbleEvents, cancelableEvents));
}
break;
case "NetStream.Play.Reset":
break;
case "NetStream.Play.Start":
if(autoPlay)
{
setStatus(Pyro.STATUS_PLAYING);
}
startTime = getTimer();
adjustSize();
dispatchEvent(new PyroEvent(PyroEvent.STARTED, bubbleEvents, cancelableEvents));
break;
case "NetStream.Play.Stop":
stopped = true;
adjustSize();
dispatchEvent(new PyroEvent(PyroEvent.STOPPED, bubbleEvents, cancelableEvents));
break;
case "NetStream.Seek.Notify":
if (status != Pyro.STATUS_STOPPED) { dispatchEvent(new PyroEvent(PyroEvent.SEEKED, bubbleEvents,
cancelableEvents)); }
break;
case "NetStream.Play.StreamNotFound":
setStatus(Pyro.STATUS_STOPPED);
dispatchEvent(new ErrorEvent(ErrorEvent.FILE_NOT_FOUND_ERROR, evt.info.code, bubbleEvents,
cancelableEvents));
break;
case "NetStream.Unpause.Notify":
dispatchEvent(new PyroEvent(PyroEvent.UNPAUSED, bubbleEvents, cancelableEvents));
break;
case "NetStream.Play.NoSupportedTrackFound":
case "NetStream.Seek.Failed":
case "NetStream.Failed":
case "NetStream.Play.Failed":
case "NetStream.Play.FileStructureInvalid":
case "NetStream.Play.InsufficientBW":
case "NetStream.Publish.BadName":
case "NetStream.Record.Failed":
dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, evt.info.code, bubbleEvents, cancelableEvents));
break;
case "NetStream.Play.Switch":
break;
case "NetStream.Publish.Idle":
case "NetStream.Publish.Start":
case "NetStream.Unpublish.Success":
case "NetStream.Play.UnpublishNotify":
case "NetStream.Play.UnpublishNotify":
case "NetStream.Record.Start":
case "NetStream.Record.NoAccess":
case "NetStream.Record.Stop":
break;
}
if(flushed && stopped)
{
resetInternalState();
_status = Pyro.STATUS_COMPLETED;
dispatchEvent(new PyroEvent(PyroEvent.COMPLETED, bubbleEvents, cancelableEvents));
}
}
Original comment by nib...@gmail.com
on 4 Jul 2009 at 8:48
Original comment by nib...@gmail.com
on 4 Jul 2009 at 8:49
Original issue reported on code.google.com by
marciodi...@gmail.com
on 4 Jul 2009 at 8:50