Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.Lib;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.NetStatusEvent;
- import flash.events.SecurityErrorEvent;
- import flash.media.Video;
- class Test extends Video
- {
- static var connection:NetConnection;
- public static function main() {
- #if (flash9 || flash10)
- haxe.Log.trace = function(v,?pos) { untyped __global__["trace"](pos.className+"#"+pos.methodName+"("+pos.lineNumber+"):",v); }
- #elseif flash
- haxe.Log.trace = function(v,?pos) { flash.Lib.trace(pos.className+"#"+pos.methodName+"("+pos.lineNumber+"): "+v); }
- #end
- connection = new NetConnection();
- connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- connection.client = new CustomClient();
- connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
- connection.connect("rtmp://zeus/flvplayback");
- // connection.connect(null);
- trace("Connection triggered");
- }
- static private function netStatusHandler(event:NetStatusEvent) {
- trace("Event: " + event.info.code);
- switch (event.info.code) {
- case "NetConnection.Connect.Success":
- connectStream();
- case "NetStream.Play.StreamNotFound":
- trace("Stream not found: ");
- }
- }
- static private function securityErrorHandler(event:SecurityErrorEvent) {
- trace("securityErrorHandler: " + event);
- }
- static private function connectStream() {
- try{
- var stream = new NetStream(connection);
- stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- stream.client = new CustomClient();
- stream.bufferTime = 1.0;
- var video:Video = new Video(640,360);
- video.attachNetStream(stream);
- flash.Lib.current.addChild(video);
- stream.play("ts_2_257_256");
- //stream.play("http://zeus:8090/test.flv");
- //stream.play("7Zwerge.flv");
- }catch(e:Dynamic){
- trace("Error: " + e);
- }
- }
- }
- class CustomClient {
- public function new() {}
- public function onMetaData(info:Dynamic) {
- trace("METADATA");
- trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
- }
- public function onCuePoint(info:Dynamic) {
- trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
- }
- public function onBWCheck():Int {
- trace("ON BWCHECK");
- return 0;
- }
- public function onBWDone(__arguments__ : Array<Dynamic>) {
- trace("BANDWIDTH DONE");
- var p_bw:Int = 0;
- if (__arguments__.length > 0) p_bw = __arguments__[0];
- // your application should do something here
- // when the bandwidth check is complete
- trace("bandwidth = " + p_bw + " Kbps.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment