Now you can create the structure to handle the client-side processing of the application. For this example, you will test everything within the Flash authoring environment:
Copy the bufferingStrategies.fla file in to you local application folder.
Note: There is also a bufferingStrategies_final.fla file for your reference.
The following code should appear in your Actions panel:
function init(){
// Create a NetConnection for the video application
nc_video = new NetConnection();
nc_video.onStatus = function(info) {
trace("Level: "+info.level+" Code: "+info.code);
// Initialize the stream after the connection is successful
if (info.code == "NetConnection.Connect.Success") {
trace("--- connected to: " + this.uri);
initStream("athens2004_1580");
}
};
// Once the NetConnection and its methods are created, try to connect to the FCS
nc_video.connect("rtmp:/bufferingStrategies");
}
function initStream(s_stream){
// create a netstream
ns_video = new NetStream(nc_video);
// optional onStatus handler
ns_video.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
};
// attach the NetStream to a video object called v_videoObj
v_videoObj.attachVideo(ns_video);
ns_video.play(s_stream, 0); // "0" tells the FCS to play a recorded stream without testing for a live stream first
displayData(n_bw, n_br, n_vLen);
}
function displayData(n_bw, n_br, n_vLen) {
this.onEnterFrame = function () {
tf_bufferLength.text = ns_video.bufferLength;
}
n_bw != undefined ? (tf_bandwidth.text = n_bw + " kbps") : (tf_bandwidth.text = "N/A");
n_br != undefined ? (tf_bitrate.text = n_br + " kbps") : (tf_bitrate.text = "N/A");
n_vLen != undefined ? (tf_videoLength.text = n_vLen + " s") : (tf_videoLength.text = "N/A");
ns_video.bufferTime != undefined ? (tf_bufferTime.text = ns_video.bufferTime + " s") : (tf_bufferTime.text = "N/A");
}
init();
stop();
The previous code performs the following operations:
nc_video) for the video application and attempts to establish a connection to the FCS server.initStream function and passing the name of the recorded stream to be played.initStream function creates a new NetStream instance called ns_video, attaches the stream to a video object called v_videoObj, and then starts the stream.Test the application by selecting Control > Test Movie from the menu or pressing Control+Enter. Depending on the connection speed to your FCS server, you may see some stuttering while the video plays. This example did not set the bufferTime property of the stream, so the default value is 0. This means the stream plays immediately.
I have provided text fields to the right of the video to help demonstrate my process. These fields are populated by the displayData function from your previous code. In this example, only the bufferTime and bufferLength properties will be displayed. If the video does not play, use the trace statements to help with debugging.