来源:http://www.cuplayer.com/player/PlayerCodeAs/2012/0913404.html
利用NetStream的以下属性:
bufferTime — 缓冲区大小。可设置(单位为秒),默认为0.1秒
bufferLength — 已进入缓冲区的秒数
bufferLength / bufferTime — 已缓冲的百分比
bytesLoaded — 已下载的字节数
bytesTotal — 总字节数
bytesLoaded / bytesTotal — 已下载的百分比
- package {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- public class Sample0623 extends Sprite
- {
- private var textBox:TextField;
- private var ns:NetStream;
- public function Sample0623()
- {
- //Video
- var nc:NetConnection = new NetConnection();
- nc.connect(null);
- ns = new NetStream(nc);
- ns.client = this;
- ns.bufferTime = 5;
- ns.play("demo.flv");
- var video:Video = new Video();
- video.attachNetStream(ns);
- this.addChild(video);
- //Text
- textBox = new TextField();
- textBox.autoSize = TextFieldAutoSize.CENTER;
- textBox.multiline = true;
- textBox.x = 100;
- textBox.y = 250;
- this.addChild(textBox);
- stage.addEventListener(Event.ENTER_FRAME,onEnterFrame);
- }
- private function onEnterFrame(event:Event):void
- {
- textBox.text = "";
- textBox.appendText("酷播cuplayer缓冲区大小是:"+ns.bufferTime+"\n");
- textBox.appendText("已进入缓冲区的秒数:"+ns.bufferLength+"\n");
- textBox.appendText("已缓冲的百分比:"+ Math.round((ns.bufferLength/ns.bufferTime)*100) +"%\n");
- textBox.appendText("已下载的字节数:"+ns.bytesLoaded+"\n");
- textBox.appendText("酷播cuplayer总字节数:"+ns.bytesTotal+"\n");
- textBox.appendText("已下载的百分比:"+ Math.round((ns.bytesLoaded/ns.bytesTotal)*100) +"%\n");
- }
- public function onMetaData(infoObject:Object):void
- {
- }
- }
- }
时间: 2024-10-03 14:56:09