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