March 7, 2021
Hot Topics:

Adobe's Emerging Rich Media Ecosystem, Part 1: Developing Social Media Applications

  • By Marcia Gulesian
  • Send Email »
  • More Articles »


Connecting to the server—the NetConnection class

Before a client can play audio and video from Flash Media Server, it must connect to the server. The connection request is accepted or rejected by an application instance on the server, and connection messages are sent back to the client. Once the application accepts the connection request, a connection is available to both the client and the server.

Users connect to the server through a network connection (see Figure 3). A connection is similar to a large pipe and can carry many streams of data. Each stream travels in one direction and transports content between one client and the server. Each server can handle many connections concurrently, with the number determined by your server capacity.

Click here for a larger image.

Figure 3: Connecting to the server with the NetConnection class

Managing connections—connection status codes

Once the connection between client and server is made, it can break for various reasons. The network might go down, the server might stop, or the connection might be closed from the server or the client. Any change in the connection status creates a netStatus event, which has both a code and a level property describing the change.

Multiple bit rate switching

Adobe Flash Media Server can encode and deliver On2 V6 and Sorenson Spark-encoded video. Flash Player 8 and 9 support both codecs, whereas Flash Player 7 and earlier versions support only the Sorenson Spark codec.

You can create virtual directories on the server to store copies of video streams in each format. This lets your application deliver the highest quality content to clients based on their Flash Player version. The next article in this series will have more to say about codecs.

Detecting bandwidth

Matching a data stream to the client's bandwidth capacity is perhaps the most important factor in ensuring a good playback experience. Once you have detected a user's bandwidth, you can:

  • Choose a video encoded at a bit rate appropriate for the user's bandwidth speed.
  • Play a video and set the buffer size based on the detected bandwidth.

In Adobe Flash Media Server, bandwidth detection is built in to the server. The new bandwidth detection, called native bandwidth detection, provides better performance and scalability. To use native bandwidth detection, make sure bandwidth detection is enabled, and write client code that calls functions built in to Adobe Flash Media Server.

With native bandwidth detection, you can use any version of ActionScript on the client. You do not need to add or change server-side code. If you prefer to use your existing server-side bandwidth detection code from a previous release of Flash Media Server, you can disable native bandwidth detection by configuring BandwidthDetection in Application.xml.

Detecting stream length

The server-side Stream class allows you to detect the length of a recorded stream. The Stream class has a static method, length(), that returns the length in seconds of an audio or video stream. The length is measured by Adobe Flash Media Server and differs from the duration that onMetaData returns, which is set by a user or a tool.

Buffering streams dynamically

Buffering a video stream helps ensure that the video plays smoothly, without interruption. Buffering manages fluctuations in bandwidth while a video is playing. These fluctuations can occur due to changes in a network connection or server load, or to additional work being done on the client computer.

To create the best experience for users, monitor the progress of a video and manage buffering as the video downloads. You may need to set different buffer sizes for different users, to ensure the best playback experience. One choice is to detect a user's bandwidth.

While the stream is playing, you also can detect and handle netStatus events. For example, when the buffer is full, the netStatus event returns an info.code value of NetStream.Buffer.Full. When the buffer is empty, another event fires with a code value of NetStream.Buffer.Empty. When the data is finished streaming, the NetStream.Buffer.Flush event is dispatched. You can listen for these events and set the buffer size smaller when empty and larger when full.

Note: Flash Player 9 Update 3 no longer clears the buffer when a stream is paused. This allows viewers to resume playback without experiencing any hesitation. Developers also can use NetStream.pause() in code to buffer data while viewers are watching a commercial, for example, and then unpause the stream when the main video starts.


About the Author

Marcia Gulesian is an IT strategist, hands-on practitioner, and advocate for business-driven architectures. She has served as software developer, project manager, CTO, and CIO. Marcia is the author of well more than 100 feature articles on IT, its economics, and its management.

Page 3 of 3

This article was originally published on April 1, 2008

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date