Commiting to continue stuff at home
[swf-overlay.git] / MusicBox.as
1 package {
2 import flash.media.Sound;
3 import flash.media.SoundChannel;
4 import flash.net.URLRequest;
5 import flash.events.Event;
6
7 public class MusicBox {
8
9 private var streamInfo:StreamInfo;
10 private var tracks:Array;
11 private var playing:Boolean;
12 private var looping:Boolean;
13 private var shuffling:Boolean;
14
15 public function MusicBox(streamInfo:StreamInfo) {
16 this.streamInfo = streamInfo;
17 this.tracks = new Array();
18 this.playing = false;
19 this. looping = false;
20 this.shuffling = false;
21 this.streamInfo.addEventListener(StreamInfo.INFO_UPDATE, this.setTrackNames);
22 }
23
24 public function play() {
25 this.playing = true;
26 }
27
28 private function setTrackNames(e:Event) {
29 var trackNames = this.streamInfo.getStreamParameter("MusicBoxTracks").split(',').map(Util.trim);
30 for each(var trackName in trackNames) {
31 var track:Object = {name: trackName, sound: false}
32 this.tracks.push(track);
33 }
34
35 this.loadTracks();
36 }
37
38 private function loadTracks() {
39 for each(var track in this.tracks) {
40 var snd:Sound = new Sound();
41 snd.load(new URLRequest(this.streamInfo.getStreamParameter("MusicBoxBase") + "/" + track.name));
42
43 snd.addEventListener(Event.COMPLETE, function(e:Event) {
44 track.sound = snd;
45 });
46 }
47
48 }
49 }
50
51 }