<?xml version="1.0" encoding="utf-8"?>
<mx:Application pageTitle="My FMS Video Player (Wanna Get Rocked)" xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initApp()" creationComplete="PageLoaded()" layout="vertical" backgroundImage="images/flum.jpg" backgroundColor="cyan">
<mx:HTTPService id="videoService" url="theVideos.xml" showBusyCursor="true" />
<mx:Script>
<![CDATA[
import mx.events.VideoEvent;
import mx.controls.Alert;
[Bindable] private var dp:Array;
[Bindable] private var bgimage:String = "";
private var blnLoadDelayRunOnce:Boolean = false;
private function initApp():void {
vidDisplay.autoBandWidthDetection = false;
vidDisplay.source = "rtmp://your_domain/videos/defleppard_photograph.flv";
videoService.send();
}
private function PageLoaded():void {
var myTimer:Timer = new Timer(1000, 0);
myTimer.addEventListener("timer", onTimer);
myTimer.start();
}
private function onTimer(event:TimerEvent):void {
if (!blnLoadDelayRunOnce) {
readytoContinue();
}
}
private function readytoContinue():void {
if (videoService.lastResult.videos.video!=undefined) {
var aryTemp:Array = new Array();
for (var i:Number=0; i<videoService.lastResult.videos.video.length; i++) {
aryTemp.push({name: videoService.lastResult.videos.video[i].name, label: videoService.lastResult.videos.video[i].label});
}
dp = aryTemp;
cbxVideo.dataProvider = dp;
}
blnLoadDelayRunOnce = true;
}
private function playVideo(stream:String):void {
if (stream!=null) {
vidDisplay.autoBandWidthDetection = false;
vidDisplay.source = "rtmp://your_domain/videos/" + stream + ".flv";
vidDisplay.addEventListener(Event.COMPLETE, onComplete);
vidDisplay.play();
btnPlay.enabled = false;
btnMute.enabled = true;
btnPause.enabled = true;
btnStop.enabled = true;
swfLoad.source = "delirio.swf";
}
}
private function onComplete(event:Event):void {
swfLoad.source = null;
btnPlay.enabled = true;
btnMute.enabled = false;
btnPause.enabled = false;
btnStop.enabled = false;
}
private function pauseVideo(stream:String):void {
if (stream!=null) {
vidDisplay.pause();
btnPlay.enabled = true;
swfLoad.source = null;
}
}
private function stopVideo(stream:String):void {
if (stream!=null) {
vidDisplay.stop();
vidDisplay.close();
btnStop.enabled = false;
btnPause.enabled = false;
btnMute.enabled = false;
btnPlay.enabled = true;
swfLoad.source = null;
}
}
private function muteVideo(stream:String):void {
if (stream!=null && btnMute.label=='Mute') {
vidDisplay.volume = 0;
btnMute.label = "Sound On";
swfLoad.source = null;
} else if (stream!=null && btnMute.label=='Sound On') {
vidDisplay.volume = 1;
btnMute.label = "Mute";
swfLoad.source = "delirio.swf";
}
}
private function viewSource():void {
var u:URLRequest = new URLRequest("srcview/index.html");
navigateToURL(u,"_blank");
}
]]>
</mx:Script>
<mx:Panel title="Rock it to me" color="#E21C51" height="{vidDisplay.height + 80}" width="{vidDisplay.width + 40}" horizontalAlign="center" verticalAlign="middle">
<mx:VideoDisplay id="vidDisplay" source="{null}" autoPlay="false" maintainAspectRatio="true"/>
<mx:HBox>
<mx:Button id="btnPlay" label="Play" click="playVideo(cbxVideo.selectedItem.name)" enabled="false"/>
<mx:Button id="btnPause" label="Pause" click="pauseVideo(cbxVideo.selectedItem.name)" enabled="false"/>
<mx:Button id="btnStop" label="Stop" click="stopVideo(cbxVideo.selectedItem.name)" enabled="false"/>
<mx:Button id="btnMute" label="Mute" click="muteVideo(cbxVideo.selectedItem.name)" enabled="false"/>
</mx:HBox>
</mx:Panel>
<mx:ComboBox id="cbxVideo" dataProvider="{dp}" labelField="label" change="playVideo(cbxVideo.selectedItem.name)" toolTip="Select the video you want to play..."/>
<mx:Spacer height="10"/>
<mx:SWFLoader id="swfLoad" source="{null}" width="50" height="50" click="viewSource()" toolTip="Click to view the source..."/>
</mx:Application>