Newer
Older
TUplayer / src / TUplayer.mxml
@reddawg reddawg on 19 Mar 2008 5 KB Updates
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="360" 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;
	private var onPause:Boolean = false;
	private var t:Timer;
	private var scrubbing:Boolean = false;
	
	/* 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);
      
      t = new Timer(500,0);
      t.addEventListener(TimerEvent.TIMER,timerHander);
      }
      
    /* 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 {
      var min:Number = Math.floor(info.duration/60);
      var sec:Number = Math.floor(info.duration%60);
      var secStr:String;
      
      if (sec < 10)
        secStr = "0" + sec.toString();
      else
        secStr = sec.toString();

      fTime.text = min + ":" + secStr;
    	
   	  tvVid.width = info.width;
   	  tvVid.height = info.height;
   	  timeLine.maximum = info.duration;
   	  
   	  if ((300 - info.height) > 0) {
   	    tvVid.y = ((300 - info.height)/2);
   	    }
   	  else {
   	    tvVid.y = 0;
   	    }
      }
	  
	public function tvNetStatus(e:NetStatusEvent):void {
	  switch (e.info.code) {
        case "NetStream.Play.Start":
          t.start();
          break;
        case "NetStream.Play.StreamNotFound":
        case "NetStream.Play.Stop":
          t.stop();
          break;
	    case "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);
          break;
	    }
	  }
	  
	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 {
		//Alert.show("test");
	  }
	  
    public function updateVolume():void	{
	  var st:SoundTransform = tvNS.soundTransform;
	  st.volume = (volume.value) * .01;
	  tvNS.soundTransform = st;
      } /* End updateVolume */
      
    private function doPause():void {
      if (onPause == true) {
      	pB.label = "||";
      	tvNS.resume();
      	onPause = false;
        }
      else {
      	pB.label = ">";
      	tvNS.pause();
      	onPause = true; 
        }
    }
    
    private function timerHander(event:TimerEvent):void {
      var min:Number = Math.floor(tvNS.time/60);
      var sec:Number = Math.floor(tvNS.time%60);
      var secStr:String;
      
      if (sec < 10)
        secStr = "0" + sec.toString();
      else
        secStr = sec.toString();

      cTime.text = min + ":" + secStr;
      
      if (scrubbing == false)
        timeLine.value = tvNS.time;
      }
      
	public function scrubVideo(event:Event):void
			{
				if (scrubbing == true) {
				tvNS.seek(timeLine.value);
				scrubbing=false;
				}
			}
			

	]]>
</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" id="pB" label="||" click="doPause()"  paddingLeft="0" paddingRight="0" width="28"/>
        <mx:HSlider id="timeLine" snapInterval="0.5" value="0" width="138" liveDragging="true" click="scrubbing=true" change="scrubVideo(event)"/>
        <mx:Label id="cTime" text="000:00"  fontSize="10" fontWeight="bold"/>
        <mx:Label id="fTime" text="000:00"  fontWeight="bold" color="#C60808" paddingBottom="0" fontSize="10"/>
        <mx:HSlider liveDragging="true" minimum="0" id="volume" snapInterval="1" value="50" maximum="100" change="updateVolume()" width="89"/>
      </mx:ControlBar>
    </mx:Panel>
</mx:Application>