--- /dev/null
+package {
+ import flash.events.Event;
+
+ public class MusicBox {
+
+ private var streamInfo:StreamInfo;
+ private var trackNames:Array;
+
+ public function MusicBox(streamInfo:StreamInfo) {
+ this.streamInfo = streamInfo;
+ this.streamInfo.addEventListener(StreamInfo.INFO_UPDATE, this.setTrackNames);
+ }
+
+ private function setTrackNames(e:Event) {
+ this.trackNames = this.streamInfo.getStreamParameter("MusicBoxTracks").split(',').map(Util.trim);
+ for(var i in this.trackNames) {
+ trace(i + " " + this.trackNames[i]);
+ }
+ }
+ }
+
+}
public class Overlay extends flash.display.MovieClip {
private var streamInfo:StreamInfo;
-
+ private var musicBox:MusicBox;
+
/*
* After doing some science, 50ms seems to be roughly the time it takes
* for a request to complete and for the locking to not happen.
*/
- private const REFRESH_RATE = 500;
+ private const REFRESH_RATE = 50;
public function Overlay() {
this.streamInfo = new StreamInfo("Cam", REFRESH_RATE);
+ this.musicBox = new MusicBox(this.streamInfo);
+
this.streamInfo.addEventListener(StreamInfo.INFO_UPDATE, this.streamInfoUpdated);
}
private function streamInfoUpdated(e:Event) {
- trace(this.streamInfo.getLastUpdated());
+ for each(var i in this.streamInfo.getLastUpdated()) {
+ trace(i + " has been updated to " + this.streamInfo.getStreamParameter(i));
+ }
}
}
private function parseVars(lines:Array) {
var broadcastUpdate = false;
for each(var line in lines) {
- var keyValue = line.split("=", 2);
+ var keyValue = line.split("=", 2).map(Util.trim);
if(keyValue.length == 2) {
if(this.streamInfo[keyValue[0]] != keyValue[1]) {
if(!broadcastUpdate) {
--- /dev/null
+package {
+
+ public class Util {
+
+ public static function trim(str:String, index:int, array:Array):String {
+ if(str == null) {
+ return "";
+ }
+
+ return str.replace(/^\s+|\s+$/g, "");
+ }
+
+ }
+
+}