Mercurial > hg > audiodb
comparison bindings/as3/examples/simpletest/src/Example.as @ 737:18974af682cf
* Tweaks to event strings for safety
* Fixed mis-firing event in Bridge
* Added a simple example
* Added packaging
author | mas01mj |
---|---|
date | Thu, 16 Sep 2010 11:39:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
736:e7cf6b9c7944 | 737:18974af682cf |
---|---|
1 package | |
2 { | |
3 | |
4 import org.omras2.audiodb.Bridge; | |
5 import org.omras2.audiodb.SearchEvent; | |
6 import org.omras2.audiodb.SoundEvent; | |
7 import org.omras2.audiodb.model.SearchResult; | |
8 | |
9 import flash.display.Sprite; | |
10 import flash.media.Sound; | |
11 /** | |
12 * @author mikej | |
13 */ | |
14 public class Example extends Sprite | |
15 { | |
16 private var _bridge : Bridge; | |
17 private var _sounds : Array; | |
18 | |
19 public function Example() | |
20 { | |
21 this._bridge = new Bridge("http://0.0.0.0:8080"); | |
22 this._sounds = []; | |
23 | |
24 // Find the tracks similar to AWAL1000 | |
25 _bridge.addEventListener(SearchEvent.COMPLETE, this.handleSearchComplete); | |
26 _bridge.search("AWAL1000"); | |
27 } | |
28 | |
29 private function handleSearchComplete(event : SearchEvent) : void | |
30 { | |
31 // Now grab the first 20s of the first result | |
32 _bridge.addEventListener(SoundEvent.COMPLETE, this.handleSoundLoaded); | |
33 | |
34 var query : SearchResult = (event.results[0] as SearchResult); | |
35 _bridge.getSound(query.uid, query.ipos, 5); | |
36 | |
37 var closestMatch : SearchResult = event.results[1] as SearchResult; | |
38 | |
39 _bridge.getSound(closestMatch.uid, closestMatch.ipos , 5); | |
40 } | |
41 | |
42 private function handleSoundLoaded(event : SoundEvent) : void | |
43 { | |
44 _sounds.push(event.sound); | |
45 if(_sounds.length == 2) | |
46 { | |
47 for each(var sound : Sound in _sounds) | |
48 { | |
49 sound.play(); | |
50 } | |
51 } | |
52 } | |
53 } | |
54 } |