Newer
Older
TUplayer / src / TUplayer.mxml
@reddawg reddawg on 19 Mar 2008 4 KB Start Of TUplayer
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="351" creationComplete="initApp()" backgroundColor="#FFFFFF">
  <mx:Style>
    Panel {
      borderAlpha: 1;
      borderThicknessLeft: 0;
      borderThicknessTop: 0;
      borderThicknessBottom: 0;
      borderThicknessRight: 0;
      roundedBottomCorners: true;
      cornerRadius: 8;
      headerHeight: 23;
      highlightAlphas: 0, 0.12;
      headerColors: #2e2e2e, #8F8C8C;
      footerColors: #4e84df, #0f6cc3;
      titleStyleName: "myPanelTitle";
      }
    .myPanelTitle {
      color: #ffffff;
      fontSize: 11;
      fontWeight:normal;
      }
    ControlBar {
      paddingTop:2px;
      paddingBottom:2px;
      height:15px;
      }
  </mx:Style>
  <mx:Script>
  <![CDATA[
  	import mx.collections.ArrayCollection;
	
	import mx.controls.Alert;
	
    /* Variables */
  	private var gateway:NetConnection;         // AMF Gateway
	private var tvVid:Video;
	private var cVid:Number;
	private var curVid:ArrayCollection;
	
	/* Streams */  	
    public var tvNC:NetConnection;        // NetConnection For Sync Video
    public var tvNS:NetStream;            // NetStream For Sync Video
    public var tvST:SoundTransform;       // SoundTransform For Sync Video
    
    private function initApp():void {
      /* Initialize the AMF gateway */	
      gateway = new NetConnection();
      gateway.connect("http://www.ubixonline.com/amfphp/gateway.php");
      
      
      /* Set up sync stream */
      tvNC = new NetConnection;
      tvNC.addEventListener(NetStatusEvent.NET_STATUS, tvNetStatus);
      tvNC.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
      tvNC.client = this;
      tvNC.objectEncoding = ObjectEncoding.AMF3;
      tvNC.connect("rtmp://rtmp.UbixOnline.com/oflaDemo");
      
      /* Set Up Video */
      tvVid = new Video(400,300);
      vidHolder.addChild(tvVid);
      cVid = Number(Application.application.parameters.vid);
      }
      
    /* AMF Fault Handlers */
    public function onFault(fault:String):void {
      Alert.show("Error: " + fault.toString());
      }
	public function onBWDone():void {
	  //Alert.show("Called BWDONE");
	  }
	  
    public function onMetaData(info:Object):void {
   	  tvVid.width = info.width;
   	  tvVid.height = info.height;
   	  
   	  if ((300 - info.height) > 0) {
   	    tvVid.y = ((300 - info.height)/2);
   	    }
   	  else {
   	    tvVid.y = 0;
   	    }
      }
	  
	public function tvNetStatus(e:NetStatusEvent):void {
	  if (e.info.code == "NetConnection.Connect.Success") {
	    if (tvST != null)
	      tvST = null;
	        
	      if (tvNS != null)
	        tvNS = null;
	        
          tvNS = new NetStream(tvNC);
          tvNS.client = this;
          tvVid.attachNetStream(tvNS);
    	  tvNS.close();       
          tvST = tvNS.soundTransform;
          tvNS.addEventListener(NetStatusEvent.NET_STATUS, tvNetStatus,false,0,true);
          gateway.call("tuve.pVid",new Responder(gotVid,null),cVid);
	    }
	  }
	  
	private function gotVid(result:Array):void {
	  if (result) {
	  	curVid = null;
	  	curVid = new ArrayCollection(result);
        tvNS.play(curVid[0].file);	  	 
	    }
	  }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
	  Alert.show("securityError: " + event.text);
      }

	public function onPlayStatus(info:Object):void {
	  }
	  
    public function updateVolume():void	{
	  var st:SoundTransform = tvNS.soundTransform;
	  st.volume = (volume.value) * .01;
	  tvNS.soundTransform = st;
      } /* End updateVolume */

	]]>
</mx:Script>
    <mx:Panel id="vidContainer" width="400" backgroundColor="#000000" height="351">
      <mx:UIComponent id="vidHolder" x="400" y="0" width="400" height="300"/>
      <mx:ControlBar>
        <mx:Button x="407" y="302" label="||" click="tvNS.pause()"  paddingLeft="0" paddingRight="0" width="28"/>
        <mx:Button x="443" y="302" label="&gt;" click="tvNS.resume()"  paddingLeft="0" paddingRight="0" width="27"/>
        <mx:HSlider liveDragging="true" minimum="0" id="volume" snapInterval="1" value="75" maximum="100" change="updateVolume()" width="150" x="616" y="304"/>
      </mx:ControlBar>
    </mx:Panel>
</mx:Application>