<?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;
/* 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") {
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);
}
public function updateVolume():void {
var st:SoundTransform = tvNS.soundTransform;
st.volume = (volume.value) * .01;
tvNS.soundTransform = st;
//tvMaster.tvSO.data.volume = volume.value;
} /* End updateVolume */
]]>
</mx:Script>
<mx:HBox horizontalGap="0" width="800" backgroundColor="#000000">
<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:VBox>
<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=">" click="tvNS.resume()" paddingLeft="0" paddingRight="0" width="27"/>
<mx:Button x="478" y="302" label=">>" 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:VBox>
</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="Video" />
</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>