分享

视频流播放 双阀值缓冲

 windli笔记 2016-02-20
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();

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多