function initConnection() {
// Create a NetConnection
nc = new NetConnection();
// Define onStatus event handler
nc.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);
startStream(); //Inizialize the stream
}
};
// try to connect, to be changed with your app path
nc.connect("rtmp://127.0.0.1/dualBuffering/demo");
}
function startStream() {
//Define stream and buffers parameters
stream_name="test_stream"; //your stream
startBufferLength=2; //keep this in the range 2-4+
expandedBufferLength=15; //arbitrarily high
// create a netstream
ns = new NetStream(nc);
// Define onStatus event handler
ns.onStatus = function(infoObject:Object) {
if (infoObject["code"]=="NetStream.Buffer.Full"){
ns.setBufferTime(expandedBufferLength);
trace("set expanded buffer");
}
if (infoObject["code"]=="NetStream.Buffer.Empty"){
ns.setBufferTime(startBufferLength);
trace("set start buffer");
}
}
// attach the NetStream to a video object
// change from videoObj to your istance name if needed
videoObj.attachVideo(ns);
ns.setBufferTime(startBufferLength);
ns.play(stream_name, 0);
}
initConnection();
stop();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。