Advertisement
nanyobis

NsExampleVideoSizeEqualsStageSize4.as

Aug 9th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.accessibility.Accessibility;
  4.     import flash.display.Sprite;
  5.     import flash.events.*;
  6.     import flash.net.NetConnection;
  7.     import flash.net.NetStream;
  8.     import flash.media.Video;
  9.  
  10.     public class NsExample extends Sprite
  11.     {
  12.         private var nc:NetConnection;
  13.         private var ns:NetStream;
  14.         private var video:Video;
  15.        
  16.         public function NsExample()
  17.         {
  18.             video = new Video();
  19.             addChild(video);   
  20.            
  21.             nc = new NetConnection();
  22.             nc.client=this;
  23.             nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
  24.             nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onError);
  25.             nc.connect('rtmp://live.7cast.net/live');
  26.         }
  27.  
  28.         private function startStreaming()
  29.         {
  30.             ns = new NetStream(nc);
  31.             ns.client = this;
  32.             ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
  33.             ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onError);
  34.             ns.play("ovaxh37k9yep18z");
  35.             video.attachNetStream(ns);
  36.         }
  37.        
  38.         private function onNetStatus(event:NetStatusEvent):void
  39.         {
  40.             switch(event.info.code)
  41.             {
  42.                 case 'NetConnection.Connect.Success':
  43.                 trace('NetConnection.Connect.Success');
  44.                 startStreaming();
  45.                 break;
  46.                
  47.                 default:
  48.                 trace(event.info.code);
  49.             }
  50.         }
  51.         private function onError(event:AsyncErrorEvent):void
  52.         {
  53.             trace(event);
  54.         }
  55.         public function onMetaData(data)
  56.         {
  57.             for(var i in data){ trace(i + " = " + data[i])}
  58.             video.scaleY = video.scaleX;
  59.             video.width = stage.stageWidth
  60.             video.x = (stage.stageWidth - video.width)/2;
  61.             video.y = (stage.stageHeight - video.height)/2;
  62.         }
  63.         public function onBWDone ()
  64.         {
  65.             trace("on Bandwidth Done ");
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement