Guest User

Untitled

a guest
Nov 30th, 2010
1,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.Lib;
  2. import flash.net.NetConnection;
  3. import flash.net.NetStream;
  4. import flash.events.NetStatusEvent;
  5. import flash.events.SecurityErrorEvent;
  6. import flash.media.Video;
  7.  
  8. class Test extends Video
  9. {
  10.    static var connection:NetConnection;
  11.  
  12.    public static function main() {
  13.  
  14.  
  15.      #if (flash9 || flash10)
  16.      haxe.Log.trace = function(v,?pos) { untyped __global__["trace"](pos.className+"#"+pos.methodName+"("+pos.lineNumber+"):",v); }
  17.      #elseif flash
  18.      haxe.Log.trace = function(v,?pos) { flash.Lib.trace(pos.className+"#"+pos.methodName+"("+pos.lineNumber+"): "+v); }
  19.      #end
  20.  
  21.      connection = new NetConnection();
  22.      connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
  23.      connection.client = new CustomClient();
  24.      connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
  25.      connection.connect("rtmp://zeus/flvplayback");
  26.      // connection.connect(null);
  27.      trace("Connection triggered");
  28.    }
  29.  
  30.    static private function netStatusHandler(event:NetStatusEvent) {
  31.             trace("Event: " + event.info.code);
  32.             switch (event.info.code) {    
  33.                 case "NetConnection.Connect.Success":
  34.                     connectStream();
  35.                 case "NetStream.Play.StreamNotFound":
  36.                     trace("Stream not found: ");
  37.             }
  38.         }
  39.  
  40.    static private function securityErrorHandler(event:SecurityErrorEvent) {
  41.             trace("securityErrorHandler: " + event);
  42.         }
  43.  
  44.         static private function connectStream() {
  45.             try{
  46.                var stream = new NetStream(connection);
  47.                stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
  48.                stream.client = new CustomClient();
  49.                stream.bufferTime = 1.0;
  50.                var video:Video = new Video(640,360);
  51.                video.attachNetStream(stream);
  52.                flash.Lib.current.addChild(video);
  53.                stream.play("ts_2_257_256");
  54.                //stream.play("http://zeus:8090/test.flv");
  55.                //stream.play("7Zwerge.flv");
  56.             }catch(e:Dynamic){
  57.                trace("Error: " + e);
  58.             }  
  59.            
  60.         }
  61.  
  62. }
  63.  
  64. class CustomClient {
  65.  
  66.     public function new() {}
  67.  
  68.     public function onMetaData(info:Dynamic) {
  69.         trace("METADATA");
  70.         trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
  71.     }
  72.     public function onCuePoint(info:Dynamic) {
  73.         trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
  74.     }
  75.  
  76.         public function onBWCheck():Int {
  77.                 trace("ON BWCHECK");
  78.             return 0;
  79.         }
  80.        
  81.         public function onBWDone(__arguments__ : Array<Dynamic>) {
  82.                 trace("BANDWIDTH DONE");   
  83.                 var p_bw:Int = 0;
  84.                 if (__arguments__.length > 0) p_bw = __arguments__[0];
  85.                     // your application should do something here
  86.                     // when the bandwidth check is complete
  87.                 trace("bandwidth = " + p_bw + " Kbps.");
  88.         }
  89.  
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment