Forums » General Discussion Search

AS3 API (including upload!) New Reply

Author Post
Posts: 26
Registered: Sep 10, 2008

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

Posts: 5
Registered: Nov 13, 2009

Strange, I can't access the documentation. It gives me some XML error response and says access denied.

Posts: 26
Registered: Sep 10, 2008

I've just moved the documentation to http://also.github.com/echo-nest-flash-api/asdoc/.

Posts: 9
Registered: Dec 03, 2009

hi also, I am trying to upload using your library, but is seems that your "uploadFileData" that you put in the example in your post does not exist. And in the TrackApi.as you mention it in the comments: "@see #uploadFileData()", but in also in your documentation there is no public or private function with this name.

Am i not getting it? I hope you can help me, because i am a novice user, but very eager!

Posts: 9
Registered: Dec 03, 2009

hi also, i got it to work, because i used the example code that was at http://github.com/also/echo-nest-flash-api/. i included it for other forum visitors:

var fileReference:FileReference;

private function chooseFile():void { fileReference = new FileReference(); fileReference.addEventListener(Event.SELECT, function(e:Event):void { uploadFile(); }); fileReference.browse(); }

private function uploadFile():void { trackApi.uploadFileReference({file: fileReference}, { onResponse: function(track:Object):void { trace('id: ' + track.id + ', md5: ' + track.md5);}, onEchoNestError: function(error:EchoNestError):void { trace(error.code + ': ' + error.description); } }); }

But thanks for you work, it works although i find it sometimes hard to read/understand how e.g. your void within a void within a void is build up.

Reply to this Thread

You must log in to post a reply.