Newer
Older
TUvod / src / TUvod.mxml
@reddawg reddawg on 20 Feb 2008 5 KB *** empty log message ***
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="800"  creationComplete="initApp();" height="600">
  <mx:Script>
  <![CDATA[
    import mx.controls.Alert;
    import mx.collections.ArrayCollection;

    /* Variables */
  	public var gateway:NetConnection;         // AMF Gateway
	[Bindable]
	public var songList:ArrayCollection;
	[Bindable]
	public var playList:ArrayCollection;
	
	public var tvVid:Video;

  	/* 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);
      
      playList = new ArrayCollection();
      
      findSong(true);
      }
      
    public function findSong(ia:Boolean):void {
      var searchOptV:Object = new Object();
      searchOptV.skey = ""; //searchBox.text;
      searchOptV.sclass = 1; //Number(tvMaster.tvClass[selC.selectedIndex].@data);
      searchOptV.srating = 4; //Number(tvMaster.tvRating[selR.selectedIndex].@data);
      searchOptV.exclusive = 0; //tvMaster.chanExclusive;
      searchOptV.stime = 0; //tvTime.text;
      if (ia == true)
        searchOptV.inca = 2;
      else
        searchOptV.inca = 1;
      gateway.call("tuve.findSongsVOD",new Responder(getSongs,onFault),searchOptV);	
      }
      
    public function getSongs(result:Array):void {
      if (result != null) {
      	songList = null;
      	songList = new ArrayCollection(result);;
        }
      else {
      	songList = null;
      	songList = new ArrayCollection;
        }
      }

    /* 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) {
   	  	  tvSyncVid.y = ((300 - info.height)/2);
   	      }
   	    else {
   	      tvVid.y = 0;
   	      }
   	      */
   	    //tvOverlay.y = tvSyncVid.y + (tvSyncVid.height - 29);
   	    /*
   	    if ((400 - info.width) > 0) {
   	      tvVid.x = ((400 - info.width)/2);
   	      }
   	    else {
   	      tvVid.x = 0;
   	      }
   	      */
   	    //tvOverlay.x = tvSyncVid.x + (tvSyncVid.width - 31);
      }
	  
	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);
          //masterObject.updateVolume();
          /*
          if (tvSyncFailed == true) {
          	masterObject.chatWindow.htmlText += "<TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Verdana\" SIZE=\"10\" COLOR=\"#990000\" LETTERSPACING=\"0\" KERNING=\"0\">[" + fmtdDate() + "] RTMP: Successfully Reconnected To Streaming Service.</FONT></P></TEXTFORMAT>";
          	if (myCount > 0)
          	  tvSyncNS.play(curSong,tvTotal - myCount);
          	tvSyncFailed = false;
            }
            */
	    }
	  }

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

	public function onPlayStatus(info:Object):void {
	  if (info.code == "NetStream.Play.Complete") {
        playList.removeItemAt(0);
        if (playList.length >= 1)
          tvNS.play(playList[0].file,0);	  	
	    }
	  }
    private function addSong():void {
      playList.addItem({file:sList.selectedItem.file,videoTitle:sList.selectedItem.artist + " - " + sList.selectedItem.title});
      if (playList.length == 1)
        tvNS.play(playList[0].file,0);
      }
    private function delSong():void {
      if (pList.selectedIndex == 0)
        if (playList.length > 1)
          tvNS.play(playList[0].file,0);
      playList.removeItemAt(pList.selectedIndex);
      }
    private function skipVideo():void {
      tvNS.close();
      playList.removeItemAt(0);
      if (playList.length >= 1)
        tvNS.play(playList[0].file,0);
      }
  ]]>
  </mx:Script>
  <mx:HBox horizontalGap="0" width="800">
  <mx:DataGrid width="100%" height="100%" dataProvider="{playList}" id="pList" doubleClickEnabled="true" doubleClick="delSong()">  	
    <mx:columns>
      <mx:DataGridColumn dataField="videoTitle" headerText="Video" />
    </mx:columns>
  </mx:DataGrid>
  <mx:UIComponent id="vidHolder" x="400" y="0" width="400" height="300"/>
</mx:HBox>


  <mx:DataGrid id="sList" x="0" y="330" width="100%" height="100%" dataProvider="{songList}" doubleClickEnabled="true" doubleClick="addSong()">
    <mx:columns>
      <mx:DataGridColumn itemRenderer="searchRow" headerText="Video" />
    </mx:columns>
  </mx:DataGrid>
  <mx:Button x="412" y="302" label="||" click="tvNS.pause()"  paddingLeft="0" paddingRight="0" width="28"/>
  <mx:Button x="448" y="302" label="&gt;" click="tvNS.resume()"  paddingLeft="0" paddingRight="0" width="27"/>
  <mx:Button x="483" y="302" label="&gt;&gt;" click="skipVideo()"  paddingLeft="0" paddingRight="0" width="29"/>
</mx:Application>