|
Hi,
I've created an ActionScript 3 version of the Echo Nest track API.
It includes all the API methods, including upload (which requires Flash 10).
The code is here: http://github.com/also/echo-nest-flash-api/
API documentation: http://static.ryanberdeen.com/projects/echo-nest-flash-api/asdoc/index.html
An example:
var trackApi:TrackApi = new TrackApi();
trackApi.apiKey = 'EJ1B4BFNYQOC56SGF';
trackApi.getMode({id: 'music://id.echonest.com/~/TR/TRLFPPE11C3F10749F'}, {
onResponse: function(mode:Array):void {
trace('Mode: ' + mode[0] +', confidence: ' + mode[1]); // Mode: 1, confidence: 1
}
});
Uploading (both chooseFile() and uploadFile() must happen in response to user clicks):
var fileReference:FileReference;
private function chooseFile():void {
fileReference = new FileReference();
fileReference.addEventListener(Event.SELECT, function(e:Event):void {
fileReference.addEventListener(Event.COMPLETE, function(e:Event):void {
// file loaded, call uploadFile next
trace('loaded ' + fileReference.name);
});
fileReference.load();
});
fileReference.browse();
}
private function uploadFile():void {
trackApi.uploadFileData(fileReference.data, {
onResponse: function(track:Object):void {
trace('id: ' + track.id + ', md5: ' + track.md5); // id: music://id.echonest.com/~/TR/TRMVA0211BC6E08329, md5: 2f45abacba9e9d2312afa63a8df10d23
},
onEchoNestError: function(error:EchoNestError):void {
trace(error.code + ': ' + error.description);
}
});
}
I hope this is useful; let me know if you use it! I'll be adding the artist API soon.
Ryan
|