User Guide
92 Application Development Tips and Tricks
Managing bandwidth
You can control the amount of data the server sends to each client by providing an
approximate bandwidth capacity. You can do so in several ways. One way is to configure the
capacity for the Flash Media Server in the configuration file (Config.xml). For more
information on this technique, see Managing Flash Media Server. Another way is to use
NetStream.receiveVideo() to specify the frame rate per second of the incoming video. A
third way to match the data flow with capacity is to use
Camera.setQuality() on the client
side and
Client.setBandwidthLimit() on the server side to inform the server of the client’s
capacity.
Another option for managing bandwidth is, in Flash Player, the NetStream class provides
properties for playing Flash Video (FLV) files from Flash Media Server. An event handler
(
onStatus()) is invoked when a status is changed or an error is posted in the NetStream. A
status message,
NetStream.Play.InsufficientBW, shows that data playing through the
NetStream is slower than the normal speed.
Data can be slower than normal speed for many reasons. For example, the client can have
insufficient bandwidth or the server can be busy and not send data at the expected rate. The
status message,
NetStream.Play.InsufficientBW, provides feedback to the client so that
the client can manage the situation. The
NetStream.Play.InsufficientBW message is
passed to the
onStatus() handler as an Info object:
For more information about Info objects, see Appendix A, “Client-Side Information Objects”
in the Client-Side ActionScript Language Reference for Flash Media Server 2.
The design can be as simple as displaying a warning message, as in the following:
ns = new NetStream(nc);
ns.onStatus = function(info){
if (info.code == "NetStream.Play.InsufficientBW")
trace("Warning: data is behind");
}
vid.attachVideo(ns);
ns.setBufferTime(2);
ns.play("foo", 0, -1, true);
Code property Level
NetStream.Play.InsufficientBW warning