mas01mj@737: package mas01mj@737: { mas01mj@737: mas01mj@737: import org.omras2.audiodb.Bridge; mas01mj@737: import org.omras2.audiodb.SearchEvent; mas01mj@737: import org.omras2.audiodb.SoundEvent; mas01mj@737: import org.omras2.audiodb.model.SearchResult; mas01mj@737: mas01mj@737: import flash.display.Sprite; mas01mj@737: import flash.media.Sound; mas01mj@737: /** mas01mj@737: * @author mikej mas01mj@737: */ mas01mj@737: public class Example extends Sprite mas01mj@737: { mas01mj@737: private var _bridge : Bridge; mas01mj@737: private var _sounds : Array; mas01mj@737: mas01mj@737: public function Example() mas01mj@737: { mas01mj@737: this._bridge = new Bridge("http://0.0.0.0:8080"); mas01mj@737: this._sounds = []; mas01mj@737: mas01mj@737: // Find the tracks similar to AWAL1000 mas01mj@737: _bridge.addEventListener(SearchEvent.COMPLETE, this.handleSearchComplete); mas01mj@737: _bridge.search("AWAL1000"); mas01mj@737: } mas01mj@737: mas01mj@737: private function handleSearchComplete(event : SearchEvent) : void mas01mj@737: { mas01mj@737: // Now grab the first 20s of the first result mas01mj@737: _bridge.addEventListener(SoundEvent.COMPLETE, this.handleSoundLoaded); mas01mj@737: mas01mj@737: var query : SearchResult = (event.results[0] as SearchResult); mas01mj@737: _bridge.getSound(query.uid, query.ipos, 5); mas01mj@737: mas01mj@737: var closestMatch : SearchResult = event.results[1] as SearchResult; mas01mj@737: mas01mj@737: _bridge.getSound(closestMatch.uid, closestMatch.ipos , 5); mas01mj@737: } mas01mj@737: mas01mj@737: private function handleSoundLoaded(event : SoundEvent) : void mas01mj@737: { mas01mj@737: _sounds.push(event.sound); mas01mj@737: if(_sounds.length == 2) mas01mj@737: { mas01mj@737: for each(var sound : Sound in _sounds) mas01mj@737: { mas01mj@737: sound.play(); mas01mj@737: } mas01mj@737: } mas01mj@737: } mas01mj@737: } mas01mj@737: }