Basic work on music box
authorCameron Ball <c.ball1729@gmail.com>
Fri, 17 Apr 2015 08:13:18 +0000 (16:13 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Fri, 17 Apr 2015 08:13:18 +0000 (16:13 +0800)
MusicBox.as [new file with mode: 0644]
Overlay.as
StreamInfo.as
Util.as [new file with mode: 0644]

diff --git a/MusicBox.as b/MusicBox.as
new file mode 100644 (file)
index 0000000..ebec49c
--- /dev/null
@@ -0,0 +1,22 @@
+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]);
+                       }
+               }
+       }
+       
+}
index 97d6b38..e288330 100644 (file)
@@ -6,20 +6,25 @@
        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));
+                       }
                }
 
        }
index 6ae479a..d27f3ca 100644 (file)
@@ -74,7 +74,7 @@
                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) {
diff --git a/Util.as b/Util.as
new file mode 100644 (file)
index 0000000..6f7fcae
--- /dev/null
+++ b/Util.as
@@ -0,0 +1,15 @@
+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, "");
+               }
+
+       }
+       
+}