Newer
Older
TUvod / src / TUvod.mxml
@reddawg reddawg on 28 Feb 2008 8 KB Visual Enhancements
<?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" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#000000, #8F8C8C]">
<!--
#efaa15, #e6780c;
-->
  <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.controls.Alert;
    import mx.collections.ArrayCollection;

    /* Variables */
  	private var gateway:NetConnection;         // AMF Gateway
	[Bindable]
	private var songList:ArrayCollection;
	[Bindable]
	private var playList:ArrayCollection;
	private var tvVid:Video;
	private var tvPlaying:Boolean = false;
	
	/* Data */
	[Bindable]
	public var tvRating:XMLList = 
	  <>
	    <mi label="G" data="1" />
	    <mi label="PG" data="2" />
	    <mi label="13+" data="3" />
	    <mi label="MA" data="4" />
	    <mi label="AD" data="5" />
	  </>;

    [Bindable]
    public var tvClass:XMLList = 
      <>
        <mi label="All" data="0" />
        <mi label="Anime/Toons" data="3" />
        <mi label="Documentary" data="5" />
        <mi label="Movie" data="4" />
        <mi label="Music" data="1" />
        <mi label="TV" data="2" />
        <mi label="Original" data="6" />
      </>;

  	/* 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();
      
      vClass.selectedIndex = 0;
      vRating.selectedIndex = 2;
      findSong(true);
      }
      
    public function findSong(ia:Boolean):void {
      var searchOptV:Object = new Object();
      searchOptV.skey = searchBox.text;
      searchOptV.sclass = Number(tvClass[vClass.selectedIndex].@data);
      searchOptV.srating = Number(tvRating[vRating.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) {
   	    tvVid.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")
        if (playList.length >= 1) {
          tvNS.play(playList[0].file,0);
          vidContainer.title = playList[0].videoTitle;
          playList.removeItemAt(0);
          }
        else
          tvPlaying = false;
	  }
	  
    private function addSong():void {
      playList.addItem({file:sList.selectedItem.file,videoTitle:sList.selectedItem.artist + " - " + sList.selectedItem.title});
      if ((playList.length == 1) && (tvPlaying == false)) {
        tvNS.play(playList[0].file,0);
        vidContainer.title = playList[0].videoTitle;
        playList.removeItemAt(0);
        tvPlaying = true;
        }
      }
 
    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();
      if (playList.length >= 1) {
        tvNS.play(playList[0].file,0);
        vidContainer.title = playList[0].videoTitle;
        playList.removeItemAt(0);
        }
      }
      
    public function updateVolume():void	{
	  var st:SoundTransform = tvNS.soundTransform;
	  st.volume = (volume.value) * .01;
	  tvNS.soundTransform = st;
      } /* End updateVolume */
  ]]>
  </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="Playlist" />
      </mx:columns>
    </mx:DataGrid>
    <mx:Panel id="vidContainer" cornerRadius="0" width="400" backgroundColor="#000000">
      <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:Button x="478" y="302" label="&gt;&gt;" click="skipVideo()"  paddingLeft="0" paddingRight="0" width="29"/>
        <mx:HSlider liveDragging="true" minimum="0" id="volume" snapInterval="1" value="75" maximum="100" change="updateVolume()" width="150" x="616" y="304"/>
        <mx:Image id="loud" source="@Embed('assets/audio-volume-high 16x16.png')" click="volume.value = 100; updateVolume();"  x="774" y="306"/>
      </mx:ControlBar>
    </mx:Panel>
  </mx:HBox>


  <mx:DataGrid id="sList" x="399" y="351" width="401" height="100%" dataProvider="{songList}" doubleClickEnabled="true" doubleClick="addSong()">
    <mx:columns>
      <mx:DataGridColumn itemRenderer="searchRow" headerText="Search Results" />
    </mx:columns>
  </mx:DataGrid>
  <mx:TextInput id="searchBox" x="0" y="351" width="398" enter="findSong(true)" />
  <mx:ComboBox x="0" y="375" width="115" id="vClass" dataProvider="{tvClass}" labelField="@label"  paddingLeft="0" paddingRight="0"/>
  <mx:ComboBox x="123" y="375" width="60" id="vRating" dataProvider="{tvRating}" labelField="@label"  paddingLeft="0" paddingRight="0"/>
  <mx:Button x="191" y="375" label="Search" click="findSong(true)" />
</mx:Application>