<?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.Image;
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;
private var tvOverlay:Image;
/* 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);
/*
if (Application.application.parameters.aS == "true")
aS = true;
*/
tvOverlay = new Image();
tvOverlay.width = 27;
tvOverlay.height = 25;
tvOverlay.x = 369;
tvOverlay.y = 271;
tvOverlay.source = "http://www.ubixonline.com/images/tvOverLay.png";
vidHolder.addChild(tvOverlay);
t = new Timer(500,0);
t.addEventListener(TimerEvent.TIMER,timerHander);
}
/* AMF Fault Handlers */
public function onFault(fault:String):void {
trace("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;
}
if ((400 - info.width) > 0) {
tvVid.x = ((400 - info.width)/2);
}
else {
tvVid.x = 0;
}
tvOverlay.y = tvVid.y + (tvVid.height - 29);
tvOverlay.x = tvVid.x + (tvVid.width - 31);
}
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);
updateVolume();
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 {
trace("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;
}
}
private function gotoUrl():void {
var webPageURL:URLRequest;
//if (aS == false) {
webPageURL = new URLRequest("http://www.tuve.tv/watch/" + cVid.toString());
navigateToURL(webPageURL, '_new');
//}
}
]]>
</mx:Script>
<mx:Panel id="vidContainer" width="400" backgroundColor="#000000" height="351">
<mx:UIComponent id="vidHolder" x="400" y="0" width="400" height="300" click="gotoUrl()" />
<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="40" maximum="100" change="updateVolume()" width="89"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>